Commit Graph

1009 Commits

Author SHA1 Message Date
Douglas Gregor 0be31a2eb7 Move the "current scope" state from the Parser into Action. This
allows Sema some limited access to the current scope, which we only
use in one way: when Sema is performing some kind of declaration that
is not directly driven by the parser (e.g., due to template
instantiatio or lazy declaration of a member), we can find the Scope
associated with a DeclContext, if that DeclContext is still in the
process of being parsed. 

Use this to make the implicit declaration of special member functions
in a C++ class more "scope-less", rather than using the NULL Scope hack.

llvm-svn: 107491
2010-07-02 17:43:08 +00:00
Douglas Gregor dc13ded606 Implement C++ DR481, which clarifies that the scope of template
parameters starts at the end of the template-parameter rather than at
the point where the template parameter name is encounted. For example,
given:

  typedef unsigned char T;
  template<typename T = T> struct X0 { };

The "T" in the default argument refers to the typedef of "unsigned
char", rather than referring to the newly-introduced template type
parameter 'T'. 

Addresses <rdar://problem/8122812>.

llvm-svn: 107354
2010-07-01 00:00:45 +00:00
Chandler Carruth 2d69ec7a72 Partial fix for PR7267 based on comments by John McCall on an earlier patch.
This is more targeted, as it simply provides toggle actions for the parser to
turn access checking on and off. We then use these to suppress access checking
only while we parse the template-id (included scope specifier) of an explicit
instantiation and explicit specialization of a class template. The
specialization behavior is an extension, as it seems likely a defect that the
standard did not exempt them as it does explicit instantiations.

This allows the very common practice of specializing trait classes to work for
private, internal types. This doesn't address instantiating or specializing
function templates, although those apparently already partially work.

The naming and style for the Action layer isn't my favorite, comments and
suggestions would be appreciated there.

llvm-svn: 106993
2010-06-28 08:39:25 +00:00
Duncan Sands d3e231eb3c Add parentheses suggested by gcc.
llvm-svn: 106668
2010-06-23 19:34:52 +00:00
Chris Lattner 37141f4fb4 improve altivec vector bool/pixel support, patch by Anton Yartsev
with several tweaks by me.

llvm-svn: 106619
2010-06-23 06:00:24 +00:00
Argyrios Kyrtzidis 75000b6814 Fix PR7180.
For

void f( a:🅱️:c );

we would cache the tokens "a:🅱️:" but then we would try to annotate them using the range "a::".
Before annotating them with the (invalid) C++ scope spec, set it to the range of "a:🅱️:".

llvm-svn: 106536
2010-06-22 11:30:04 +00:00
Douglas Gregor 9377c8230b When semantic analysis fail to introduce a class or class template,
just skip over the body of the class or class template: it's a
semantic disaster that's likely to cause invariants to break. Fixes
part of <rdar://problem/8104754>.

llvm-svn: 106496
2010-06-21 22:31:09 +00:00
Argyrios Kyrtzidis e1224c8aba Cure for Doug's insomnia.
llvm-svn: 106394
2010-06-19 19:58:34 +00:00
Fariborz Jahanian ef5f621215 Implements Sema part of init_priority(priority) attribute
(radar 8076356) - wip.

llvm-svn: 106322
2010-06-18 21:44:06 +00:00
Argyrios Kyrtzidis e9b76afe4f Make sure the caching mechanism in Parser::ParseLexedMethodDefs is robust against the parser reading too few tokens.
llvm-svn: 106214
2010-06-17 10:52:22 +00:00
Argyrios Kyrtzidis 355094ef06 Make sure parens/braces/brackets are correctly balanced.
In a line like:

(;

the semicolon leaves Parser:ParenCount unbalanced (it's 1 even though we stopped looking for a right paren).
This may affect later parsing and result in bad recovery for parsing errors.

llvm-svn: 106213
2010-06-17 10:52:18 +00:00
Ted Kremenek 24c8e4f245 Per conversation with Doug, remove two assertions in ParseLexedMethodDefs() that
didn't indicate violated invariants but that we weren't recovering well.

llvm-svn: 106195
2010-06-17 00:59:17 +00:00
Alexis Hunt c675ec09f0 Update CMake build for new attribute changes.
llvm-svn: 106188
2010-06-17 00:37:02 +00:00
Douglas Gregor 428119e39a When parsing cached C++ method declarations/definitions, save the
"previous token" location at the end of the class definition. This
eliminates a badly-placed error + Fix-It when the ';' following a
class definition is missing. Fixes <rdar://problem/8066414>.

llvm-svn: 106175
2010-06-16 23:45:56 +00:00
Douglas Gregor 13d0568ecc Make the "extra ';' inside a struct or union" diagnostic more
precise. Fixes PR7336.

llvm-svn: 106170
2010-06-16 23:08:59 +00:00
Douglas Gregor bb1196534c When we see a 'template' disambiguator that marks the next identifier
(or operator-function-id) as a template, but the context is actually
non-dependent or the current instantiation, allow us to use knowledge
of what kind of template it is, e.g., type template vs. function
template, for further syntactic disambiguation. This allows us to
parse properly in the presence of stray "template" keywords, which is
necessary in C++0x and it's good recovery in C++98/03.

llvm-svn: 106167
2010-06-16 23:00:59 +00:00
Douglas Gregor f7d7771812 Fix the recently-added warning about 'typename' and 'template'
disambiguation keywords outside of templates in C++98/03. Previously,
the warning would fire when the associated nested-name-specifier was
not dependent, but that was a misreading of the C++98/03 standard:
now, we complain only when we're outside of any template.

llvm-svn: 106161
2010-06-16 22:31:08 +00:00
Douglas Gregor 9938e3b11b Add some missing parentheses, from Anton Yartsev
llvm-svn: 106101
2010-06-16 15:28:57 +00:00
Chris Lattner f3d3b36870 Allow an asm label specifier on C++ methods, like GCC does.
Patch by David Majnemer!

llvm-svn: 105909
2010-06-13 05:34:18 +00:00
Daniel Dunbar ee6b692551 Makefiles: Set Clang CPP compiler flags in a single location, instead of scattered throughout the project Makefiles.
llvm-svn: 105638
2010-06-08 20:44:43 +00:00
Daniel Dunbar e6c1daa8fd Makefile: Switch Clang Makefiles to always include the top-level Clang Makefile.
- This eliminates most dependencies on how Clang is installed relative to LLVM.

llvm-svn: 105637
2010-06-08 20:34:18 +00:00
Abramo Bagnara d73405829b Added AccessSpecDecl node.
llvm-svn: 105525
2010-06-05 05:09:32 +00:00
Douglas Gregor 71b209dea6 Properly disambiguate between an elaborated-type-specifier and a
type-parameter within a template parameter list. Found by inspection. 

llvm-svn: 105462
2010-06-04 07:30:15 +00:00
Daniel Dunbar 6906b04457 Fix compiler warning about to false -> pointer conversion; patch by Dimitry Andric!
llvm-svn: 105328
2010-06-02 15:47:03 +00:00
Chris Lattner 47054fbbe9 Minor tweaks on doug's objc recovery patch: the caller
of isSimpleObjCMessageExpression checks the language,
so change a dynamic check into an assert.

isSimpleObjCMessageExpression is expensive, so only do it
in the common case when it is likely to matter: when the [
of the postfix expr starts on a new line.  This should avoid
doing lookahead for every array expression.

llvm-svn: 105229
2010-05-31 18:18:22 +00:00
Douglas Gregor 990ccace5b When we see the a '[' in a postfix expression in Objective-C, perform
a simple, quick check to determine whether the expression starting
with '[' can only be an Objective-C message send. If so, don't parse
it as an array subscript expression. This improves recovery for, e.g.,

  [a method1]
  [a method2]

so that we now produce

  t.m:10:13: error: expected ';' after expression
  [a method]
            ^

instead of some mess about expecting ']'.

llvm-svn: 105221
2010-05-31 14:40:22 +00:00
Douglas Gregor d5a479cbb5 Don't try to parse class template specializations in C. It can only
lead to heartache. Fixes <rdar://problem/8044088>.

llvm-svn: 105178
2010-05-30 22:30:21 +00:00
Douglas Gregor 2683c28ff6 Improve parser recovery when we try to parse a call expression but the
called function itself is invalid (e.g., because of a semantic error
referring to that declaration). Fixes <rdar://problem/8044142>.

llvm-svn: 105175
2010-05-30 22:23:08 +00:00
Douglas Gregor 7aa6b229fe Teach code completion to adjust its completion priorities based on the
type that we expect to see at a given point in the grammar, e.g., when
initializing a variable, returning a result, or calling a function. We
don't prune the candidate set at all, just adjust priorities to favor
things that should type-check, using an ultra-simplified type system.

llvm-svn: 105128
2010-05-30 01:49:25 +00:00
Fariborz Jahanian 6e81492151 Empty enum in c is now error to match gcc's behavior.
(radar 8040068).

llvm-svn: 105011
2010-05-28 22:23:22 +00:00
John McCall 61d8258fa3 Roll back r104941.
llvm-svn: 104990
2010-05-28 18:25:28 +00:00
John McCall 2177a9b65a Add a new attribute on records, __attribute__((adl_invisible)), and define
the x86-64 __va_list_tag with this attribute.  The attribute causes the
affected type to behave like a fundamental type when considered by ADL.

(x86-64 is the only target we currently provide with a struct-based
__builtin_va_list)

Fixes PR6762.

llvm-svn: 104941
2010-05-28 08:20:36 +00:00
John McCall 08bede4c7b Don't just skip over the entire tag definition if the parser action didn't
give us a decl back.  Makes -cc1 -parse-noop handle a substantially larger
amount of the C++ grammar.

llvm-svn: 104940
2010-05-28 08:11:17 +00:00
Douglas Gregor f4c33349b5 Make -code-completion-patterns only cover multi-line code
completions. Plus, tweak a few completion patterns to better reflect
the language grammar.

llvm-svn: 104905
2010-05-28 00:22:41 +00:00
Douglas Gregor a817a19bc6 Implement a code-completion hook for the receiver of an Objective-C
message. This completion gives better results than just using the
"expression" completion, which is effectively what happened before.

llvm-svn: 104895
2010-05-27 23:06:34 +00:00
Daniel Dunbar 9c84d4a8a0 Parse/Sema: Add support for '#pragma options align=packed', which, it should be
noted, is not the same as __attribute__((packed)). That would be ridiculous!

llvm-svn: 104865
2010-05-27 18:42:17 +00:00
Daniel Dunbar 663e8094ae Parse/Sema: Add support for '#pragma options align=native'.
llvm-svn: 104864
2010-05-27 18:42:09 +00:00
Douglas Gregor 205a361413 When we've parsed a nested-name-specifier in a member access
expression, "forget" about the object type; only the
nested-name-specifier matters for name lookup purposes. Fixes PR7239.

llvm-svn: 104834
2010-05-27 15:25:59 +00:00
Daniel Dunbar 75c9be7e80 Parse: Add support for '#pragma options align'.
Also, fix a source location bug with the rparen in #pragma pack.

llvm-svn: 104784
2010-05-26 23:29:06 +00:00
Douglas Gregor 6da3db4af3 Improve code completion in failure cases in two ways:
1) Suppress diagnostics as soon as we form the code-completion
  token, so we don't get any error/warning spew from the early
  end-of-file.
  2) If we consume a code-completion token when we weren't expecting
  one, go into a code-completion recovery path that produces the best
  results it can based on the context that the parser is in.

llvm-svn: 104585
2010-05-25 05:58:43 +00:00
Chris Lattner fb58515bc3 improve the fixit for the missing : error when parsing ?:. When
there are already two spaces before the token where the : was expected,
put the : in between the spaces.  This means we get it right in both
of these cases:

t.c:2:17: error: expected ':'
  return a ? b  c;
                ^
               :
t.c:3:16: error: expected ':'
  return a ? b c;
               ^
               : 

In the later case, the diagnostic says to insert ": ", in the former
case it says to insert ":" between the spaces.  This fixes rdar://8007231

llvm-svn: 104569
2010-05-24 22:31:37 +00:00
Douglas Gregor 20c38a7c58 Improve recovery when we see a dependent template name that is missing
the required "template" keyword, using the same heuristics we do for
dependent template names in member access expressions, e.g.,

test/SemaTemplate/dependent-template-recover.cpp:11:8: error: use 'template'
      keyword to treat 'getAs' as a dependent template name
    T::getAs<U>();
       ^
       template 

Fixes PR5404.

llvm-svn: 104409
2010-05-21 23:43:39 +00:00
Douglas Gregor 786123dc48 Improve parser recovery when we encounter a dependent template name
that is missing the 'template' keyword, e.g., 

  t->getAs<T>()

where getAs is a member of an unknown specialization. C++ requires
that we treat "getAs" as a value, but that would fail to parse since T
is the name of a type. We would then fail at the '>', since a type
cannot be followed by a '>'.

This is a very common error for C++ programmers to make, especially
since GCC occasionally allows it when it shouldn't (as does Visual
C++). So, when we are in this case, we use tentative parsing to see if
the tokens starting at "<" can only be parsed as a template argument
list. If so, we produce a diagnostic with a fix-it that states that
the 'template' keyword is needed:

test/SemaTemplate/dependent-template-recover.cpp:5:8: error: 'template' keyword
      is required to treat 'getAs' as a dependent template name
    t->getAs<T>();
       ^
       template 

This is just a start of this patch; I'd like to apply the same
approach to everywhere that a template-id with dependent template name
can be parsed.

llvm-svn: 104406
2010-05-21 23:18:07 +00:00
John McCall b54367d2f8 Propagate access specifiers to anonymous union members nested within classes.
Fixes <rdar://problem/7987650>.

llvm-svn: 104376
2010-05-21 20:45:30 +00:00
Douglas Gregor 4abc32d033 Improve parser recovery when a switch condition is invalid; fixes
<rdar://problem/7971948>.

llvm-svn: 104291
2010-05-20 23:20:59 +00:00
Abramo Bagnara d754848f10 Added basic source locations to Elaborated and DependentName types.
llvm-svn: 104169
2010-05-19 21:37:53 +00:00
Ted Kremenek 26bde774df Add clang support for IBOutletCollection.
llvm-svn: 104135
2010-05-19 17:38:06 +00:00
Douglas Gregor a941dcae16 Add support for Microsoft's __thiscall, from Steven Watanabe!
llvm-svn: 104026
2010-05-18 16:57:00 +00:00
Douglas Gregor c9a99c5e5c mutable is a storage class that can follow a class/struct/union definition. Fixes PR7153
llvm-svn: 103954
2010-05-17 18:19:56 +00:00
Chris Lattner ff895c140c Improve error recovery in C/ObjC when the first argument of a function
declarator is incorrect.  Not being a typename causes the parser to 
dive down into the K&R identifier list handling stuff, which is almost
never the right thing to do.

Before:

r.c:3:17: error: expected ')'
void bar(intptr y);
                ^
r.c:3:9: note: to match this '('
void bar(intptr y);
        ^
r.c:3:10: error: a parameter list without types is only allowed in a function definition
void bar(intptr y);
         ^

After:

r.c:3:10: error: unknown type name 'intptr'; did you mean 'intptr_t'?
void bar(intptr y);
         ^~~~~~
         intptr_t
r.c:1:13: note: 'intptr_t' declared here
typedef int intptr_t;
            ^

This fixes rdar://7980651 - poor recovery for bad type in the first arg of a C function

llvm-svn: 103783
2010-05-14 17:44:56 +00:00