Commit Graph

764 Commits

Author SHA1 Message Date
Richard Smith fb8b7b9a1c PR17567: Improve diagnostic for a mistyped constructor name. If we see something
that looks like a function declaration, except that it's missing a return type,
try typo-correcting it to the relevant constructor name.

In passing, fix a bug where the missing-type-specifier recovery codepath would
drop a preceding scope specifier on the floor, leading to follow-on diagnostics
and incorrect recovery for the auto-in-c++98 hack.

llvm-svn: 192644
2013-10-15 00:00:26 +00:00
Richard Smith f39720b26e Don't get confused by a virt-specifier after a trailing-return-type - it's not
an accidentally-included name for the declarator.

llvm-svn: 192559
2013-10-13 22:12:28 +00:00
Benjamin Kramer 5fc787fc2e Parser: Avoid a crash-on-invalid when trying to diagnose function calls with -> in it.
Use the existing convenience function.

llvm-svn: 192347
2013-10-10 12:24:40 +00:00
David Majnemer 767c1f8428 Make wording for certain invalid unary expressions more consistent.
An invalid decltype expression like 'decltype int' gives:
error: expected '(' after 'decltype'

This makes it so 'sizeof int' gives a similar one:
error: expected parentheses around type name in sizeof expression

llvm-svn: 192258
2013-10-09 00:22:23 +00:00
Reid Kleckner be7a446637 -Wmicrosoft: Don't warn on non-inline pure virtual method definitions
MSVC and clang with -fms-extensions allow pure virtual methods to be
defined inline after the "= 0" tokens.  Clang warns on these because it
is not standard, but incorrectly warns on out-of-line definitions, which
are standard.

With this change, clang will only warn on inline definitions of pure
virtual methods.

Fixes some self-host warnings on out-of-line definitions of pure virtual
destructors.

llvm-svn: 192244
2013-10-08 22:45:29 +00:00
Serge Pavlov 5815940edc Fixed messages in tests.
llvm-svn: 192208
2013-10-08 17:38:38 +00:00
Serge Pavlov aa57a64ef6 Add fixits suggesting parenthesis around type name in expressions like sizeof.
This fixes PR16992 - Fixit missing when "sizeof type" found.

llvm-svn: 192200
2013-10-08 16:56:30 +00:00
Richard Smith 5b013f5050 Add compat/extension warnings for init captures.
llvm-svn: 191609
2013-09-28 05:38:27 +00:00
Richard Smith bb13c9a49d Per latest drafting, switch to implementing init-captures as if by declaring
and capturing a variable declaration, and complete the implementation of them.

llvm-svn: 191605
2013-09-28 04:02:39 +00:00
David Majnemer 68c880b5f9 AST: Handle multidimensional arrays inside of __uuidof()
We previously handled one-dimensional arrays but didn't consider the
general case.  The fix is simple: keep going through subsequent
dimensions until we get to the base element.

llvm-svn: 191493
2013-09-27 07:57:34 +00:00
David Majnemer c185aa7d92 Sema: Respect -fdelayed-template-parsing when parsing constexpr functions
Functions declared as constexpr must have their parsing delayed in
-fdelayed-template-parsing mode so as not to upset later template
instantiation.

N.B. My reading of the standard makes it seem like delayed template
parsing is at odds with constexpr.  We may want to make refinements in
other places in clang to make constexpr play nicer with this feature.

This fixes PR17334.

llvm-svn: 191484
2013-09-27 04:14:12 +00:00
Fariborz Jahanian 0dded8ab04 Revert my patch in r191155 to allow forward
class/protocol decls in @implementation and
fixup modern rewriter to handle that.
// rdar://15066233

llvm-svn: 191311
2013-09-24 17:03:07 +00:00
David Majnemer a5e92556ac Parse: Don't crash during parsing if we lack a simple-type-specifier
Summary:
Parsing cast expressions during error recovery can put us in a bad
state.  Check to see if the token for a simple-type-specifier makes
sense before further parsing.

Fixes PR17255.

Reviewers: rsmith, doug.gregor, CornedBee, eli.friedman

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1696

llvm-svn: 191159
2013-09-22 01:24:26 +00:00
Fariborz Jahanian aa78931e91 ObjectiveC: ObjC declarations, including forward class
and protocols can be at global scope only.

llvm-svn: 191155
2013-09-22 00:02:16 +00:00
Richard Trieu 406e65c8d1 Modify the uninitialized field visitor to detect uninitialized use across the
fields in the class.  This allows a better checking of member intiailizers and
in class initializers in regards to initialization ordering.

For instance, this code will now produce warnings:

class A {
  int x;
  int y;
  A() : x(y) {}  // y is initialized after x, warn here
  A(int): y(x) {} // default initialization of leaves x uninitialized, warn here
};

Several test cases were updated with -Wno-uninitialized to silence this warning.

llvm-svn: 191068
2013-09-20 03:03:06 +00:00
Benjamin Kramer a9dfa9280e As Aaron pointed out it's simpler to reject wide string availability attr messages in the parser.
llvm-svn: 190706
2013-09-13 17:31:48 +00:00
Richard Smith 1fff95c702 PR13657 (and duplicates):
When a comma occurs in a default argument or default initializer within a
class, disambiguate whether it is part of the initializer or whether it ends
the initializer.

The way this works (which I will be proposing for standardization) is to treat
the comma as ending the default argument or default initializer if the
following token sequence matches the syntactic constraints of a
parameter-declaration-clause or init-declarator-list (respectively).

This is both consistent with the disambiguation rules elsewhere (where entities
are treated as declarations if they can be), and should have no regressions
over our old behavior. I think it might also disambiguate all cases correctly,
but I don't have a proof of that.

There is an annoyance here: because we're performing a tentative parse in a
situation where we may not have seen declarations of all relevant entities (if
the comma is part of the initializer, lookup may find entites declared later in
the class), we need to turn off typo-correction and diagnostics during the
tentative parse, and in the rare case that we decide the comma is part of the
initializer, we need to revert all token annotations we performed while
disambiguating.

Any diagnostics that occur outside of the immediate context of the tentative
parse (for instance, if we trigger the implicit instantiation of a class
template) are *not* suppressed, mirroring the usual rules for a SFINAE context.

llvm-svn: 190639
2013-09-12 23:28:08 +00:00
David Majnemer 59c0ec2396 AST: __uuidof should leak through templated types
Summary:
__uuidof on templated types should exmaine if any of its template
parameters have a uuid declspec.  If exactly one does, then take it.
Otherwise, issue an appropriate error.

Reviewers: rsmith, thakis, rnk

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1419

llvm-svn: 190240
2013-09-07 06:59:46 +00:00
Richard Smith f216366e64 C++11 attributes after 'constructor-name (' unambiguously signal that we have a
constructor.

llvm-svn: 190111
2013-09-06 00:12:20 +00:00
Richard Trieu 2f58696ddd For "expected unqualified-id" errors after a double colon, and the double colon
is at the end of the line, point to the location after the double colon instead
of at the next token.  There is more context to be given this way.  In addition,
the next token can be several lines later.

llvm-svn: 190029
2013-09-05 02:31:33 +00:00
David Majnemer ad01851f32 Parser: support Microsoft syntax for 'typename typedef'
Summary:
Transform the token sequence for:
typename typedef T U;

to:
typename T typedef U;

Raise a diagnostic when this happens but only if we succeeded handling
the typename.

Reviewers: rsmith, rnk

Reviewed By: rsmith

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1433

llvm-svn: 189867
2013-09-03 22:36:22 +00:00
David Majnemer 61c39a1ccd Sema: Properly support Microsoft-mode template arguments
Summary:
There were two things known to be wrong with our implementation of MSVC
mode template arguments:

- We didn't properly handle __uuidof/CXXUuidofExpr and skipped all type
  checking completely.
- We didn't allow for MSVC's extension of allowing certain constant
  "foldable" expressions from showing up in template arguments.
  They allow various casts dereference and address-of operations.
  We can make it more general as we find further peculiarities but this
  is the known extent.

Reviewers: rsmith, doug.gregor, rjmccall

Reviewed By: doug.gregor

CC: cfe-commits, rnk

Differential Revision: http://llvm-reviews.chandlerc.com/D1444

llvm-svn: 189087
2013-08-23 05:39:39 +00:00
Richard Smith f9b1510576 Refactor all diagnosing of TypoCorrections through a common function, in
preparation for teaching this function how to diagnose a correction that
includes importing a module.

llvm-svn: 188602
2013-08-17 00:46:16 +00:00
Eli Friedman 7a15c4af90 Fix Altivec vector literal parser hack for C++11.
It doesn't make any sense to accept "..." in the argument to a C-style cast,
so use a separate expression list parsing routine which rejects it. PR16874.

llvm-svn: 188330
2013-08-13 23:38:34 +00:00
Serge Pavlov b716b3ca1f Avoid spurious error messages if parent template class cannot be instantiated
Differential Revision: http://llvm-reviews.chandlerc.com/D924

llvm-svn: 188133
2013-08-10 05:54:47 +00:00
David Majnemer 23252a3672 Parse: Don't consider attributes of broken member declarators
ParseCXXClassMemberDeclaration was trying to use the result of
ActOnCXXMemberDeclarator to attach it to some late parsed attributes.

However when failures arise, we have no decl to attach to which
eventually leads us to a NULL pointer dereference.

While we are here, clean up the code a bit.

Fixes PR16765

llvm-svn: 187557
2013-08-01 04:22:55 +00:00
Aaron Ballman 3bf758cd65 err_attribute_not_string has been subsumed by err_attribute_argument_type.
llvm-svn: 187400
2013-07-30 01:31:03 +00:00
Richard Smith 9ce302ed9c PR5066: If a declarator cannot have an identifier, and cannot possibly be
followed by an identifier, then diagnose an identifier as being a bogus part of
the declarator instead of tripping over it. Improves diagnostics for cases like

  std::vector<const int *p> my_vec;

llvm-svn: 186061
2013-07-11 05:10:21 +00:00
David Majnemer ea5092a3b0 Sema: Do not merge new decls with invalid, old decls
Sema::MergeFunctionDecl attempts merging two decls even if the old decl
is invalid.  This can lead to interesting circumstances where we
successfully merge the decls but the result makes no sense.

Take the following for example:

template <typename T>
int main(void);

int main(void);

Sema will not consider these to be overloads of the same name because
main can't be overloaded, which means that this must be a redeclaration.

In this case the templated decl is compatible with the non-templated
decl allowing the Sema::CheckFunctionDeclaration machinery to move on
and do bizarre things like setting the previous decl of a non-templated
decl to a templated decl!

The way I see it, we should just bail from MergeFunctionDecl if the old
decl is invalid.

This fixes PR16531.

llvm-svn: 185779
2013-07-07 23:49:50 +00:00
Rafael Espindola c8c995a2bd Use the new --crash option in commands that are expected to crash.
llvm-svn: 185679
2013-07-05 02:53:30 +00:00
Rafael Espindola 925213b0fa Add 'not' to commands that are expected to fail.
This is at least good documentation, but also opens the possibility of
using pipefail.

llvm-svn: 185652
2013-07-04 16:16:58 +00:00
Richard Smith cde3fd87e0 PR16480: Reimplement token-caching for constructor initializer lists. This
previously didn't work if a mem-initializer-id had a template argument which
contained parentheses or braces.

We now implement a simple rule: just look for a ') {' or '} {' that is not
nested. The '{' is assumed to start the function-body. There are still two
cases which we misparse, where the ') {' comes from a compound literal or
from a lambda. The former case is not valid C++, and the latter will probably
not be valid C++ once DR1607 is resolved, so these seem to be of low value,
and we do not regress on them with this change. EDG and g++ also misparse
both of these cases.

llvm-svn: 185598
2013-07-04 00:13:48 +00:00
Bill Schmidt 99a084b7ae "bool" should be a context-sensitive keyword in Altivec mode.
PR16456 reported that Clang implements a hybrid between AltiVec's
"Keyword and Predefine Method" and its "Context Sensitive Keyword
Method," where "bool" is always a keyword, but "vector" and "pixel"
are context-sensitive keywords.  This isn't permitted by the AltiVec
spec.  For consistency with gcc, this patch implements the Context
Sensitive Keyword Method for bool, and stops treating true and false
as keywords in Altivec mode.

The patch removes KEYALTIVEC as a trigger for defining these keywords
in include/clang/Basic/TokenKinds.def, and adds logic for "vector
bool" that mirrors the existing logic for "vector pixel."  The test
case is taken from the bug report.

llvm-svn: 185580
2013-07-03 20:54:09 +00:00
Kaelyn Uhrain 10413a46a0 Allow typo correction to try removing nested name specifiers.
The removal is tried by retrying the failed lookup of a correction
candidate with either the MemberContext or SS (CXXScopeSpecifier) or
both set to NULL if they weren't already. If the candidate identifier
is then looked up successfully, make a note in the candidate that the
SourceRange should include any existing nested name specifier even if
the candidate isn't adding a different one (i.e. the candidate has a
NULL NestedNameSpecifier).

Also tweak the diagnostic messages to differentiate between a suggestion
that just replaces the identifer but leaves the existing nested name
specifier intact and one that replaces the entire qualified identifier,
in cases where the suggested replacement is unqualified.

llvm-svn: 185487
2013-07-02 23:47:44 +00:00
Richard Smith b80d54049b PR8302: Check for shadowing a template parameter when declaring a template
template parameter.

llvm-svn: 184884
2013-06-25 22:21:36 +00:00
Kaelyn Uhrain 52dd02d8ef Add the global namespace (the "::" namespace specifier) to the list of
namespaces to try for potential typo corrections.

llvm-svn: 184762
2013-06-24 17:49:03 +00:00
Richard Trieu 30f93859a9 Fix for PR 16367, display the name of a function in a diagnostic instead of
showing "(null)".

llvm-svn: 184377
2013-06-19 22:25:01 +00:00
Serge Pavlov 89578fd439 Recognition of empty structures and unions is moved to semantic stage
Differential Revision: http://llvm-reviews.chandlerc.com/D586

llvm-svn: 183609
2013-06-08 13:29:58 +00:00
Sylvestre Ledru 2afe2229f3 Fix a typo (chek => check)
llvm-svn: 183223
2013-06-04 13:43:50 +00:00
Aaron Ballman 317a77f1c7 Adding in parsing and the start of semantic support for __sptr and __uptr pointer type qualifiers. This patch also fixes the correlated __ptr32 and __ptr64 pointer qualifiers so that they are truly type attributes instead of declaration attributes.
For more information about __sptr and __uptr, see MSDN: http://msdn.microsoft.com/en-us/library/aa983399.aspx

Patch reviewed by Richard Smith.

llvm-svn: 182535
2013-05-22 23:25:32 +00:00
Richard Smith f44d2a8a3e PR16094: I should have known Obj-C init-capture disambiguation couldn't be
*that* easy...

Try a bit harder to disambiguate. This is mostly straightforward, but for
=-style initializers, we actually need to know where an expression ends:

  [foo = bar baz]

is a message send, whereas

  [foo = bar + baz]

is a lambda-introducer. Handle this by parsing the expression eagerly, and
replacing it with an annotation token. By chance, we use the *exact same*
parsing rules in both cases (except that we need to assume we're inside a
message send for the parse, to turn off various forms of inapplicable
error recovery).

llvm-svn: 182432
2013-05-21 22:21:19 +00:00
Fariborz Jahanian 858885578d Objective-C parsing. Error recovery when category implementation
declaration is illegally protocol qualified. // rdar://13920026

llvm-svn: 182136
2013-05-17 17:58:11 +00:00
Richard Smith ba71c08523 First pass of semantic analysis for init-captures: check the initializer, build
a FieldDecl from it, and propagate both into the closure type and the
LambdaExpr.

You can't do much useful with them yet -- you can't use them within the body
of the lambda, because we don't have a representation for "the this of the
lambda, not the this of the enclosing context". We also don't have support or a
representation for a nested capture of an init-capture yet, which was intended
to work despite not being allowed by the current standard wording.

llvm-svn: 181985
2013-05-16 06:20:58 +00:00
Richard Smith 21b3ab43e1 C++1y n3648: parse and reject init-captures for now.
llvm-svn: 181553
2013-05-09 21:36:41 +00:00
Aaron Ballman 444eb6e23c Properly parsing __declspec(safebuffers), though there is no semantic hookup. For more information about safebuffers, see MSDN: http://msdn.microsoft.com/en-us/library/dd778695(v=vs.110).aspx
llvm-svn: 181123
2013-05-04 16:58:37 +00:00
Fariborz Jahanian 46ed4d978e Objective-C parsing [qoi]: Recover gracefully with good diagnostic
when class implementation declaration adds protocol qualifier
list. // rdar://12233858

llvm-svn: 180228
2013-04-24 23:23:47 +00:00
Richard Smith 034185c2f9 The 'constexpr implies const' rule for non-static member functions is gone in
C++1y, so stop adding the 'const' there. Provide a compatibility warning for
code relying on this in C++11, with a fix-it hint. Update our lazily-written
tests to add the const, except for those ones which were testing our
implementation of this rule.

llvm-svn: 179969
2013-04-21 01:08:50 +00:00
Fariborz Jahanian d5d6f3d5a2 Objective-C++: Enable passing of modern C++11 style
initialized temporaries to objc++ methods. 
// rdar://12788429

llvm-svn: 179818
2013-04-18 23:43:21 +00:00
Fariborz Jahanian 507a5f8cb3 Objective-C parsing [qoi]: Provide good recovery when
Objective-C dictionary literals has bad syntax for the
separator. // rdar://10679157

llvm-svn: 179784
2013-04-18 19:37:43 +00:00
Argyrios Kyrtzidis 71c12fb4a3 [Parser] Handle #pragma pack/align inside C structs.
Fixes PR13580. Patch by Serge Pavlov!

llvm-svn: 179743
2013-04-18 01:42:35 +00:00