Commit Graph

698 Commits

Author SHA1 Message Date
Richard Smith d16fe12e77 'constexpr' and 'friend' are both declaration specifiers. Teach the parser this, for better error recovery.
llvm-svn: 166645
2012-10-25 00:00:53 +00:00
Eli Friedman be20d43232 Update regression tests for r166617.
llvm-svn: 166619
2012-10-24 20:28:18 +00:00
Lang Hames 720ae09c00 Fix typo, make test case slightly more reabable. Thanks to Dmitri Gribenko for
the suggestions.

llvm-svn: 166400
2012-10-21 19:56:13 +00:00
Lang Hames a930e7131c When used in a compound expression FP_CONTRACT should proceed all explicit
declarations and statements. Emit an error if the FP_CONTRACT is used
later in a compound statement.

llvm-svn: 166383
2012-10-21 01:10:01 +00:00
Richard Smith 6f21206850 DR1473: Do not require a space between operator"" and the ud-suffix in a
literal-operator-id.

llvm-svn: 166373
2012-10-20 08:41:10 +00:00
Andy Gibbs c6e68daac0 Prior to adding the new "expected-no-diagnostics" directive to VerifyDiagnosticConsumer, make the necessary adjustment to 580 test-cases which will henceforth require this new directive.
llvm-svn: 166280
2012-10-19 12:44:48 +00:00
Richard Smith 87e795174c DR1528: C++11 doesn't allow repeated cv-qualifiers in declarators after all.
llvm-svn: 166152
2012-10-17 23:31:46 +00:00
Argyrios Kyrtzidis 5c2021bf2a Handle a "#pragma options align" inside a class.
llvm-svn: 165810
2012-10-12 17:39:59 +00:00
Michael Han 23214e5046 Improve C++11 attribute parsing.
- General C++11 attributes were previously parsed and ignored. Now they are parsed and stored in AST.
- Add support to parse arguments of attributes that in 'gnu' namespace.
- Differentiate unknown attributes and known attributes that can't be applied to statements when emitting diagnostic.

llvm-svn: 165082
2012-10-03 01:56:22 +00:00
Richard Trieu 3267347cca Cleaning up the self initialization checker.
-Allow Sema to do more processing on the initial Expr before checking it.
-Remove the special conditions in HandleExpr()
-Move the code so that only one call site is needed.
-Removed the function from Sema and only call it locally.
-Warn on potentially evaluated reference variables, not just casts to r-values.
-Update tests.

llvm-svn: 164951
2012-10-01 17:39:51 +00:00
Richard Smith 0875c53239 If a comma operator is followed by a token which unambiguously indicates the
start of a statement or the end of a compound-statement, diagnose the comma as
a typo for a semicolon. Patch by Ahmed Bougacha! Additional test cases and
minor refactoring by me.

llvm-svn: 164085
2012-09-18 00:52:05 +00:00
Richard Smith 7696571d2b Recover properly after a parse error in a static_assert declaration.
llvm-svn: 163826
2012-09-13 19:12:50 +00:00
Richard Smith aa31b4b816 PR13775: When checking for a tag type being shadowed by some other declaration,
don't trample over the caller's LookupResult in the case where the check fails.

llvm-svn: 163281
2012-09-06 01:37:56 +00:00
Joao Matos 566359c0bf Revert r163083 per chandlerc's request.
llvm-svn: 163149
2012-09-04 17:49:35 +00:00
Joao Matos c32a7e4d8e Implemented parsing and AST support for the MS __leave exception statement. Also a minor fix to __except printing in StmtPrinter.cpp. Thanks to Aaron Ballman for review.
llvm-svn: 163083
2012-09-02 03:45:41 +00:00
Joao Matos e9a3ed4d71 Normalize line endings of r163013 (part 2).
llvm-svn: 163032
2012-08-31 22:18:20 +00:00
Joao Matos dc86f94f62 Improved MSVC __interface support by adding first class support for it, instead of aliasing to "struct" which had some incorrect behaviour. Patch by David Robins.
llvm-svn: 163013
2012-08-31 18:45:21 +00:00
Eli Friedman 34866c7719 Change the representation of builtin functions in the AST
(__builtin_* etc.) so that it isn't possible to take their address.
Specifically, introduce a new type to represent a reference to a builtin
function, and a new cast kind to convert it to a function pointer in the
operand of a call.  Fixes PR13195.

llvm-svn: 162962
2012-08-31 00:14:07 +00:00
Richard Smith b3afa6c483 PR13652: Don't assume the parameter array on a FunctionTypeLoc for a lambda will
be filled in; they won't if the lambda's declarator has an invalid type. Instead
take the parameters from the declarator directly.

llvm-svn: 162904
2012-08-30 13:13:20 +00:00
Aaron Ballman 3731b33009 Splitting the duplicated decl spec extension warning into two: one is an ExtWarn and the other a vanilla warning. This addresses PR13705, where const char const * wouldn't warn unless -pedantic was specified under the right conditions.
llvm-svn: 162793
2012-08-28 20:55:40 +00:00
Chad Rosier 175ea24e38 [ms-inline asm] Change the -fenable-experimental-ms-inline-asm option from a
CodeGen option to a LangOpt option.  In turn, hoist the guard into the parser 
so that we avoid the new (and fairly unstable) Sema/AST/CodeGen logic.  This
should restore the behavior of clang to that prior to r158325.
<rdar://problem/12163681>

llvm-svn: 162602
2012-08-24 21:42:51 +00:00
Richard Smith 7aed66bbee When disambiguating an expression-statement from a declaraton-statement, if the
statement starts with an identifier for which name lookup will fail either way,
look at later tokens to disambiguate in order to improve error recovery.

llvm-svn: 162464
2012-08-23 20:19:14 +00:00
Richard Smith 62e6630af9 PR13619: Make sure we're not at EOF before looking at NextToken().
llvm-svn: 162212
2012-08-20 17:37:52 +00:00
Richard Smith 4f605aff7f PR41111, PR5925, PR13210: Teach tentative parsing to annotate identifiers and
nested names as id-expressions, using the annot_primary_expr annotation, where
possible. This removes some redundant lookups, and also allows us to
typo-correct within tentative parsing, and to carry on disambiguating past an
identifier which we can determine will fail lookup as both a type and as a
non-type, allowing us to disambiguate more declarations (and thus offer
improved error recovery for such cases).

This also introduces to the parser the notion of a tentatively-declared name,
which is an identifier which we *might* have seen a declaration for in a
tentative parse (but only if we end up disambiguating the tokens as a
declaration). This is necessary to correctly disambiguate cases where a
variable is used within its own initializer.

llvm-svn: 162159
2012-08-18 00:55:03 +00:00
Chad Rosier aa7c1cb5f8 [ms-inline asm] MSVC parses multiple __asm statements on a single line as one
statement.  For example,

  if (x)
    __asm out dx, ax  __asm out dx, ax

results in a single inline asm statement (i.e., both "out dx, ax" statements are
predicated on if(x)).

llvm-svn: 161986
2012-08-15 21:03:27 +00:00
Chad Rosier c97a6bbfd8 [ms-inline asm] Add a helpful assert.
llvm-svn: 161890
2012-08-14 19:22:06 +00:00
Richard Smith 10c6072d61 In 'delete []', the '[]' never starts a lambda. Update a FIXME with a standard reference and add a test.
llvm-svn: 161604
2012-08-09 19:01:51 +00:00
Eli Friedman 971bfa11c6 Unify the codepaths for emitting deprecation warnings. The test changes are just to account for us emitting notes more consistently.
llvm-svn: 161528
2012-08-08 21:52:41 +00:00
Richard Smith 943c440455 Improvements to vexing-parse warnings. Make the no-parameters case more
accurate by asking the parser whether there was an ambiguity rather than trying
to reverse-engineer it from the DeclSpec. Make the with-parameters case have
better diagnostics by using semantic information to drive the warning,
improving the diagnostics and adding a fixit.

Patch by Nikola Smiljanic. Some minor changes by me to suppress diagnostics for
declarations of the form 'T (*x)(...)', which seem to have a very high false
positive rate, and to reduce indentation in 'warnAboutAmbiguousFunction'.

llvm-svn: 160998
2012-07-30 21:30:52 +00:00
Fariborz Jahanian a5fc75f4f5 objective-c parsing. Don't crash when selector name
is missing in method prototype. // rdar://11939584

llvm-svn: 160789
2012-07-26 17:32:28 +00:00
Richard Smith 7ac3c6af87 Pedantic -pedantic correction. Duplicate cv-qualifiers are permitted in C++11
unless they appear in a decl-specifier-seq.

llvm-svn: 160688
2012-07-24 20:24:58 +00:00
Richard Smith 45fbfc7f11 Do not warn about a function decl / direct init ambiguity if the function has a trailing return type.
llvm-svn: 160646
2012-07-23 21:41:30 +00:00
Richard Smith 87f5dc53b2 Add diagnostics for comma at end of enum and for extra semicolon at namespace
scope to -Wc++11-extensions. Move extra semicolon after member function
definition diagnostic out of -pedantic, since C++ allows a single semicolon
there. Keep it in -Wextra-semi, though, since it's still questionable.

llvm-svn: 160618
2012-07-23 05:45:25 +00:00
Nico Weber cd8a546b6c Revert r160319, it caused PR13417. Add a test for PR13417.
llvm-svn: 160542
2012-07-20 06:44:52 +00:00
Jordan Rose 12e730c6e3 Better parser recovery in Objective-C containers.
Previously it was possible to get an infinite-loop-on-invalid with a namespace
decl within @interface. Since 'namespace' is normally a safe place to retry
top-level parsing, we just didn't consume the token.

This adds a flag that tracks whether we have temporarily left Objective-C
scope to parse a C-like declaration, and uses that to better recover from
parse problems by stopping at possible method declarations and at @end. To
fix the original problem, we do /not/ stop at 'namespace' when in an
Objective-C @interface or @protocol context (but still do in @implementation).

llvm-svn: 159941
2012-07-09 16:54:53 +00:00
Richard Smith 200f47c65d A ':' after an enum-specifier at class scope is a bitfield, not a typo for a ';'.
llvm-svn: 159549
2012-07-02 19:14:01 +00:00
Jordan Rose 58d547200e Add support for the C11 _Alignof keyword.
This behaves like the existing GNU __alignof and C++11 alignof keywords;
most of the patch is simply adding the third token spelling to various places.

llvm-svn: 159494
2012-06-30 21:33:57 +00:00
Douglas Gregor 1edf57639a Support the use of "=delete" and "=default" with delayed template
parsing. Fixes <rdar://problem/11700604>.

llvm-svn: 159380
2012-06-28 21:43:01 +00:00
Richard Smith 369b9f997c Extend the "expected ';' after struct" logic to also apply to enums, and to
struct and enum forward-declarations.

llvm-svn: 159164
2012-06-25 21:37:02 +00:00
John McCall beae29a5f4 Recognize GNU attributes after 'enum class'. Fixes the libc++ build.
llvm-svn: 159089
2012-06-23 22:30:04 +00:00
Alexis Hunt 6aa9beef50 Clean up a large number of C++11 attribute parse issues, including parsing
attributes in more places where we didn't and catching a lot more issues.

This implements nearly every aspect of C++11 attribute parsing, except for:
 - Attributes are permitted on explicit instantiations inside the declarator
   (but not preceding the decl-spec)
 - Attributes are permitted on friend declarations of functions.
 - Multiple instances of the same attribute in an attribute-list (e.g.
   [[noreturn, noreturn]], not [[noreturn]] [[noreturn]] which is conforming)
   are allowed.
The first two are marked as expected-FIXME in the test file and the latter
is probably a defect and is currently untested.

Thanks to Richard Smith for providing the lion's share of the testcases.

llvm-svn: 159072
2012-06-23 05:07:58 +00:00
Fariborz Jahanian 46e14f8108 objective-c: improve diagnostic when collection expression is
not a pointer to a fast-enumerable object. // rdar://11488666

llvm-svn: 158998
2012-06-22 15:37:00 +00:00
Chad Rosier 43b7c021b3 [ms-style asm] Change the fatal error to an extension warning. Apparently, this
error was asserting on anything that included Windows.h.  MS-style inline asm is
still dropped, but at least now we're not completely silent about it.

llvm-svn: 158833
2012-06-20 18:28:37 +00:00
John McCall 5fb5df9c83 Restructure how the driver communicates information about the
target Objective-C runtime down to the frontend:  break this
down into a single target runtime kind and version, and compute
all the relevant information from that.  This makes it
relatively painless to add support for new runtimes to the
compiler.  Make the new -cc1 flag, -fobjc-runtime=blah-x.y.z,
available at the driver level as a better and more general
alternative to -fgnu-runtime and -fnext-runtime.  This new
concept of an Objective-C runtime also encompasses what we
were previously separating out as the "Objective-C ABI", so
fragile vs. non-fragile runtimes are now really modelled as
different kinds of runtime, paving the way for better overall
differentiation.

As a sort of special case, continue to accept the -cc1 flag
-fobjc-runtime-has-weak, as a sop to PLCompatibilityWeak.

I won't go so far as to say "no functionality change", even
ignoring the new driver flag, but subtle changes in driver
semantics are almost certainly not intended.

llvm-svn: 158793
2012-06-20 06:18:46 +00:00
Aaron Ballman 478faed4b0 Reapplying the changes from r158717 as they were rolled back to avoid merge conflicts from a separate problematic patch.
llvm-svn: 158750
2012-06-19 22:09:27 +00:00
Jakob Stoklund Olesen e1c0ae6fda Revert r158700 and dependent patches r158716, r158717, and r158731.
The original r158700 caused crashes in the gcc test suite,
g++.abi/vtable3a.C among others. It also caused failures in the libc++
test suite.

llvm-svn: 158749
2012-06-19 21:48:43 +00:00
Aaron Ballman 38c9ad9e72 Improves parsing and semantic analysis for MS __declspec attributes. This includes support for the align (which fixes PR12631).
llvm-svn: 158717
2012-06-19 13:49:26 +00:00
Richard Smith 7b3f322517 Extend the error recovery for a template-argument-list terminated by '>>' to
also deal with '>>>' (in CUDA), '>=', and '>>='. Fix the FixItHints logic to
deal with cases where the token is followed by an adjacent '=', '==', '>=',
'>>=', or '>>>' token, where a naive fix-it would result in a differing token
stream on a re-lex.

llvm-svn: 158652
2012-06-18 06:11:04 +00:00
Kaelyn Uhrain b5b17fe9fc Recover when correcting an unknown type name to a keyword like "struct".
llvm-svn: 158573
2012-06-15 23:45:58 +00:00
Chad Rosier 075608ecfc [ms-inline-asm] The __asm keyword is a statement separator, so multiple asm
statements are allowed on the same line.

llvm-svn: 158372
2012-06-12 20:30:26 +00:00
Chad Rosier 0764e0bb30 [ms-inline-asm] Cleanup MS style inline assembly parsing.
Specifically, improve the handling of whitespace, stop saving tokens that are
in comments and fix the case where we have a comment followed by a closing brace
on the next line.

Unfortunately, there's no easy way of testing this code.

llvm-svn: 158367
2012-06-12 19:03:42 +00:00
Richard Smith 700537cddf If parsing a trailing-return-type fails, don't pretend we didn't have one at
all. Suppresses follow-on errors mentioned in PR13074.

llvm-svn: 158348
2012-06-12 01:51:59 +00:00
Kaelyn Uhrain 493ea635fe Allow CorrectTypo to add/modify nested name qualifiers to typos that
are otherwise too short to try to correct.

The TODOs added to two of the tests are for existing deficiencies in the
typo correction code that could be exposed by using longer identifiers.

llvm-svn: 158109
2012-06-06 20:54:51 +00:00
Jordan Rose ccf43ca05c Add pedantic warning -Wempty-translation-unit (C11 6.9p1).
In standard C since C89, a 'translation-unit' is syntactically defined to have
at least one "external-declaration", which is either a decl or a function
definition. In Clang the latter gives us a declaration as well.

The tricky bit about this warning is that our predefines can contain external
declarations (__builtin_va_list and the 128-bit integer types). Therefore our
AST parser now makes sure we have at least one declaration that doesn't come
from the predefines buffer.

Also, remove bogus warning about empty source files. This doesn't catch source
files that only contain comments, and never fired anyway because of our
predefines.

PR12665 and <rdar://problem/9165548>

llvm-svn: 158085
2012-06-06 17:25:21 +00:00
John McCall 8d32c05ed4 Recognize the MS inheritance attributes and turn them into attributes
on the RecordDecl.  Persist the MS portability type attributes and
ignore them in Sema rather than the parser.

Patch by João Matos!

llvm-svn: 157288
2012-05-22 21:28:12 +00:00
John McCall fa6cf4cc9a Fix line endings.
llvm-svn: 157287
2012-05-22 21:28:07 +00:00
Douglas Gregor 6cda0715c3 Add _alignof and __builtin_alignof as aliases for __alignof in
Microsoft mode, from Will Wilson!

llvm-svn: 156940
2012-05-16 20:04:05 +00:00
Richard Trieu 2f7dc46a58 Move the warnings for extra semi-colons under -Wextra-semi. Also, added
a warning for an extra semi-colon after function definitions.  Added logic
so that a block of semi-colons on a line will only get one warning instead
of a warning for each semi-colon.

llvm-svn: 156934
2012-05-16 19:04:59 +00:00
Richard Smith a952ebbcee Don't use the implicit int rule for error recovery in C++. Instead, try to
disambiguate whether the type name was forgotten or mistyped.

llvm-svn: 156854
2012-05-15 21:01:51 +00:00
Richard Smith b71e73243b Recover properly from a redundant 'typename' before a non-nested name. This is
permitted as a Microsoft extension. Patch by William Wilson! (Plus some minor
tweaking by me.)

llvm-svn: 156786
2012-05-14 22:43:34 +00:00
Richard Smith 2f07ad5a70 Push the knowledge that we are parsing a type-id/type-name further into the
parser, and use it to emit better diagnostics in cases where an identifer
can't be looked up as a type name.

llvm-svn: 156508
2012-05-09 20:55:26 +00:00
Richard Smith 3092a3b43c Stop AltiVec parsing from going down the 'implicit int' codepath as part of its
normal parse for token sequences like 'vector pixel foo'. This incidentally also
fixes a couple of wrong-parse issues.

llvm-svn: 156503
2012-05-09 18:56:43 +00:00
Douglas Gregor d5ead14365 Restore paren, bracket and brace counts in parser when
TentativeParsingAction is reverted, from Pasi Parviainen! Fixes
PR12480 / <rdar://problem/11341251>.

llvm-svn: 155823
2012-04-30 16:20:27 +00:00
Chris Lattner 70d4498899 improve error recovery for extra ')'s after a if/switch/while condition. Before:
t.c:3:9: error: expected expression
  if (x)) {
        ^

.. which isn't even true - a statement or expression is fine.  After:

t.c:3:9: error: extraneous ')' after condition, expected a statement
  if (x)) {
        ^

This is the second part of PR12595

llvm-svn: 155762
2012-04-28 16:24:20 +00:00
Chris Lattner 02f1b61849 switch some uses of ExpectAndConsume(tok::semi to use ExpectAndConsumeSemi. This allows
us to improve this diagnostic (telling us to insert another ")":

t.c:2:19: error: expected ';' at end of declaration
  int x = 4+(5-12));
                  ^
                  ;
to:
t.c:2:19: error: extraneous ')' before ';'
  int x = 4+(5-12));
                  ^

...telling us to remove the ")".  This is PR12595.  There are more uses of ExpectAndConsumeSemi
that could be switched over, but I don't hit them on a daily basis :)

llvm-svn: 155759
2012-04-28 16:12:17 +00:00
Kaelyn Uhrain 3fe3f85769 Imrpove the note text for when a non-type decl hides a tag type
llvm-svn: 155723
2012-04-27 18:26:49 +00:00
Kaelyn Uhrain 031643ef48 Add note to help explain why a tag such as 'struct' is needed to refer
to a given type, when the reason is that there is a non-type decl with
the same name.

llvm-svn: 155677
2012-04-26 23:36:17 +00:00
Patrick Beard 0caa39474b Implements boxed expressions for Objective-C. <rdar://problem/10194391>
llvm-svn: 155082
2012-04-19 00:25:12 +00:00
Francois Pichet a39371c0e2 Emulate a MSVC bug where the creation of pointer-to-member to protected member of base class is allowed but only from a static function.
This fixes a regression when parsing MFC code with clang.

llvm-svn: 154924
2012-04-17 12:35:05 +00:00
Francois Pichet 0066db9039 The result of the Microsoft __uuidof operator must be considered a global lvalue during constant expression evaluation.
Otherwise we would get this error in C++11 mode (because of a recent change):
   error: non-type template argument of type 'const _GUID *' is not a constant expression

For code like:
template <const GUID* g = &__uuidof(struct_with_uuid)>
class COM_CLASS { };

llvm-svn: 154790
2012-04-16 04:08:35 +00:00
Richard Smith c202b2809a Add an AttributedStmt type to represent a statement with C++11 attributes
attached. Since we do not support any attributes which appertain to a statement
(yet), testing of this is necessarily quite minimal.

Patch by Alexander Kornienko!

llvm-svn: 154723
2012-04-14 00:33:13 +00:00
Erik Verbruggen 6e92251f9b Added a flag to the parser to skip method bodies.
llvm-svn: 154584
2012-04-12 10:11:59 +00:00
Richard Smith b8caac8e32 Part of PR10101: after a parse error in a declaration, try harder to find the
right place to pick up parsing. In C++, this had a tendency to skip everything
declared within headers if the TU starts with garbage.

llvm-svn: 154530
2012-04-11 20:59:20 +00:00
Richard Smith 2620cd9903 Support C++11 attributes at the start of a parameter-declaration.
llvm-svn: 154476
2012-04-11 04:01:28 +00:00
Richard Smith 3dff251da1 Parsing of C++11 attributes:
* Alternative tokens (such as 'compl') are treated as identifiers in
   attribute names.
 * An attribute-list can start with a comma.
 * An ellipsis may not be used with either of our currently-supported
   C++11 attributes.

llvm-svn: 154381
2012-04-10 03:25:07 +00:00
Richard Smith 7bdcc4a9da Disambiguation of '[[':
* In C++11, '[[' is ill-formed unless it starts an attribute-specifier. Reject
   array sizes and array indexes which begin with a lambda-expression. Recover by
   parsing the lambda as a lambda.
 * In Objective-C++11, either '[' could be the start of a message-send.
   Fully disambiguate this case: it turns out that the grammars of message-sends,
   lambdas and attributes do not actually overlap. Accept any occurrence of '[['
   where either '[' starts a message send, but reject a lambda in an array index
   just like in C++11 mode.

Implement a couple of changes to the attribute wording which occurred after our
attributes implementation landed:
 * In a function-declaration, the attributes go after the exception specification,
   not after the right paren.
 * A reference type can have attributes applied.
 * An 'identifier' in an attribute can also be a keyword. Support for alternative
   tokens (iso646 keywords) in attributes to follow.

And some bug fixes:
 * Parse attributes after declarator-ids, even if they are not simple identifiers.
 * Do not accept attributes after a parenthesized declarator.
 * Accept attributes after an array size in a new-type-id.
 * Partially disamiguate 'delete' followed by a lambda. More work is required
   here for the case where the lambda-introducer is '[]'.

llvm-svn: 154369
2012-04-10 01:32:12 +00:00
David Blaikie 80cdddc504 Fix bugs found by -Wconstant-conversion improvements currently under review.
Specifically, using a an integer outside [0, 1] as a boolean constant seems to
be an easy mistake to make with things like "x == a || b" where the author
intended "x == a || x == b".

The bug caused by calling SkipUntil with three token kinds was also identified
by a VC diagnostic & reported by Francois Pichet as review feedback for my
commit r154163. I've included test cases to verify the error recovery that was
broken/poorly implemented due to this bug.

The other fix (lib/Sema/SemaExpr.cpp) seems like that code was never actually
reached in any of Clang's tests & is related to Objective C features I'm not
familiar with, so I've not been able to construct a test case for it. Perhaps
someone else can.

llvm-svn: 154325
2012-04-09 16:37:11 +00:00
David Blaikie 89f13cb5bf Remove "parse error" in favor of more descriptive diagnostics.
In a few cases clang emitted a rather content-free diagnostic: 'parse error'.
This change replaces two actual cases (template parameter parsing and K&R
parameter declaration parsing) with more specific diagnostics and removes a
third dead case of this in the BalancedDelimiterTracker (the ctor already
checked the invariant necessary to ensure that the diag::parse_error was never
actually used).

llvm-svn: 154224
2012-04-06 23:33:59 +00:00
Patrick Beard acfbe9e1f2 Added a new attribute, objc_root_class, which informs the compiler when a root class is intentionally declared.
The warning this inhibits, -Wobjc-root-class, is opt-in for now. However, all clang unit tests that would trigger
the warning have been updated to use -Wno-objc-root-class. <rdar://problem/7446698>

llvm-svn: 154187
2012-04-06 18:12:22 +00:00
David Blaikie 3697983e19 Fix diagnostic text for r154163.
llvm-svn: 154164
2012-04-06 06:28:32 +00:00
David Blaikie cbd8125a6a Restrict fixit for missing 'class' in template template parameters.
Based on Doug's feedback to r153887 this omits the FixIt if the following token
isn't syntactically valid for the context. (not a comma, '...', identifier,
'>', or '>>')

There's a bunch of work to handle the '>>' case, but it makes for a much more
pleasant diagnostic in this case.

llvm-svn: 154163
2012-04-06 05:26:43 +00:00
David Blaikie 3a7efa2240 Improve & simplify diagnostic for missing 'class' in template template parameter.
Change suggested by Sebastian Redl on review feedback from r153887.

llvm-svn: 154102
2012-04-05 16:56:02 +00:00
Richard Smith fa0a1f531f Improve diagnostics for invalid use of non-static members / this:
* s/nonstatic/non-static/ in the diagnostics, since the latter form outvoted
  the former by 28-2 in our diagnostics.
* Fix the "use of member in static member function" diagnostic to correctly
  detect this situation inside a block or lambda.
* Produce a more specific "invalid use of non-static member" diagnostic for
  the case where a nested class member refers to a member of a
  lexically-surrounding class.

llvm-svn: 154073
2012-04-05 01:13:04 +00:00
David Blaikie f221e51d2a Correct error recovery when missing 'class' in a template template parameter.
The diagnostic message correctly informs the user that they have omitted the
'class' keyword, but neither suggests this insertion as a fixit, nor attempts
to recover as if they had provided the keyword.

This fixes the recovery, adds the fixit, and adds a separate diagnostic and
corresponding replacement fixit for cases where the user wrote 'struct' or
'typename' instead of 'class' (suggested by Richard Smith as a possible common
mistake).

I'm not sure the diagnostic message for either the original or new cases feel
very Clang-esque, so I'm open to suggestions there. The fixit hints make it
fairly easy to see what's required, though.

llvm-svn: 153887
2012-04-02 19:15:28 +00:00
Richard Smith 0191023b5a Don't try to parse a malformed parameter list after a constructor or operator
name as a direct initializer.

llvm-svn: 153628
2012-03-29 01:46:00 +00:00
Richard Smith 43f340f440 If we see '(...' where we're expecting an abstract-declarator, that doesn't
necessarily mean we've found a function declarator. If the next token is not
a ')', this is actually a parenthesized pack expansion.

llvm-svn: 153544
2012-03-27 23:05:05 +00:00
Richard Smith efd009de1c When we see 'Class(X' or 'Class::Class(X' and we suspect that it names a
constructor, but X is not a known typename, check whether the tokens could
possibly match the syntax of a declarator before concluding that it isn't
a constructor. If it's definitely ill-formed, assume it is a constructor.

Empirical evidence suggests that this pattern is much more often a
constructor with a typoed (or not-yet-declared) type name than any of the
other possibilities, so the extra cost of the check is not expected to be
problematic.

llvm-svn: 153488
2012-03-27 00:56:56 +00:00
Aaron Ballman c42d838d9f Adding some more specific tests for enum declspec parsing, to prove that it really works.
llvm-svn: 152757
2012-03-15 00:20:05 +00:00
David Blaikie 9933a5abab Fix a crash-on-invalid found by -Wlogical-op-parentheses.
llvm-svn: 152559
2012-03-12 15:39:49 +00:00
Richard Smith bfdb108fc5 Fix parsing of trailing-return-type. Types are syntactically prohibited from
being defined here: [] () -> struct S {} does not define struct S.

In passing, implement DR1318 (syntactic disambiguation of 'final').

llvm-svn: 152551
2012-03-12 08:56:40 +00:00
Richard Smith c5b0552055 Fix parsing of type-specifier-seq's. Types are syntactically allowed to be
defined here, but not semantically, so

  new struct S {};

is always ill-formed, even if there is a struct S in scope.

We also had a couple of bugs in ParseOptionalTypeSpecifier caused by it being
under-loved (due to it only being used in a few places) so merge it into
ParseDeclarationSpecifiers with a new DeclSpecContext. To avoid regressing, this
required improving ParseDeclarationSpecifiers' diagnostics in some cases. This
also required teaching ParseSpecifierQualifierList about constexpr... which
incidentally fixes an issue where we'd allow the constexpr specifier in other
bad places.

llvm-svn: 152549
2012-03-12 07:56:15 +00:00
Richard Smith bcc22fc4e1 Support for raw and template forms of numeric user-defined literals,
and lots of tidying up.

llvm-svn: 152392
2012-03-09 08:00:36 +00:00
Richard Smith 7d182a7909 Fix a couple of issues with literal-operator-id parsing, and provide recovery
for a few kinds of error. Specifically:

Since we're after translation phase 6, the "" token might be formed by multiple
source-level string literals. Checking the token width is not a correct way of
detecting empty string literals, due to escaped newlines. Diagnose and recover
from a missing space between "" and suffix, and from string literals other than
"", which are followed by a suffix.

llvm-svn: 152348
2012-03-08 23:06:02 +00:00
Richard Smith 39570d0020 Add support for cooked forms of user-defined-integer-literal and
user-defined-floating-literal. Support for raw forms of these literals
to follow.

llvm-svn: 152302
2012-03-08 08:45:32 +00:00
Richard Smith 0df56f4a90 Implement C++11 [lex.ext]p10 for string and character literals: a ud-suffix not
starting with an underscore is ill-formed.

Since this rule rejects programs that were using <inttypes.h>'s macros, recover
from this error by treating the ud-suffix as a separate preprocessing-token,
with a DefaultError ExtWarn. The approach of treating such cases as two tokens
is under discussion for standardization, but is in any case a conforming
extension and allows existing codebases to keep building while the committee
makes up its mind.

Reword the warning on the definition of literal operators not starting with
underscores (which are, strangely, legal) to more explicitly state that such
operators can't be called by literals. Remove the special-case diagnostic for
hexfloats, since it was both triggering in the wrong cases and incorrect.

llvm-svn: 152287
2012-03-08 02:39:21 +00:00
Richard Smith 75b67d6dc5 User-defined literal support for character literals.
llvm-svn: 152277
2012-03-08 01:34:56 +00:00
Richard Smith c67fdd4eb9 AST representation for user-defined literals, plus just enough of semantic
analysis to make the AST representation testable. They are represented by a
new UserDefinedLiteral AST node, which is a sugared CallExpr. All semantic
properties, including full CodeGen support, are achieved for free by this
representation.

UserDefinedLiterals can never be dependent, so no custom instantiation
behavior is required. They are mangled as if they were direct calls to the
underlying literal operator. This matches g++'s apparent behavior (but not its
actual mangling, which is broken for literal-operator-ids).

User-defined *string* literals are now fully-operational, but the semantic
analysis is quite hacky and needs more work. No other forms of user-defined
literal are created yet, but the AST support for them is present.

This patch committed after midnight because we had already hit the quota for
new kinds of literal yesterday.

llvm-svn: 152211
2012-03-07 08:35:16 +00:00
Richard Smith d67aea28f6 User-defined literals: reject string and character UDLs in all places where the
grammar requires a string-literal and not a user-defined-string-literal. The
two constructs are still represented by the same TokenKind, in order to prevent
a combinatorial explosion of different kinds of token. A flag on Token tracks
whether a ud-suffix is present, in order to prevent clients from needing to look
at the token's spelling.

llvm-svn: 152098
2012-03-06 03:21:47 +00:00
Aaron Ballman 9ecff02a45 Added support for parsing declspecs on enumerations. Fixes PR8783
llvm-svn: 151798
2012-03-01 04:09:28 +00:00
Richard Smith fa933d1225 Fix decltype crash-on-invalid, if we don't find a matching ')' for an ill-formed
decltype expression.

llvm-svn: 151515
2012-02-27 05:24:00 +00:00