Commit Graph

391 Commits

Author SHA1 Message Date
Richard Smith 42b1057244 N3922: direct-list-initialization of an auto-typed variable no longer deduces a
std::initializer_list<T> type. Instead, the list must contain a single element
and the type is deduced from that.

In Clang 3.7, we warned by default on all the cases that would change meaning
due to this change. In Clang 3.8, we will support only the new rules -- per
the request in N3922, this change is applied as a Defect Report against earlier
versions of the C++ standard.

This change is not entirely trivial, because for lambda init-captures we
previously did not track the difference between direct-list-initialization and
copy-list-initialization. The difference was not previously observable, because
the two forms of initialization always did the same thing (the elements of the
initializer list were always copy-initialized regardless of the initialization
style used for the init-capture).

llvm-svn: 252688
2015-11-11 01:36:17 +00:00
Richard Smith 9f690bd80b [coroutines] Creation of promise object, lookup of operator co_await, building
of await_* calls, and AST representation for same.

llvm-svn: 251387
2015-10-27 06:02:45 +00:00
Richard Smith cfd53b4e99 [coroutines] Initial stub Sema functionality for handling coroutine await / yield / return.
llvm-svn: 250993
2015-10-22 06:13:50 +00:00
Richard Smith 0e304ea8a1 [coroutines] Add parsing support for co_await expression, co_yield expression,
co_await modifier on range-based for loop, co_return statement.

llvm-svn: 250985
2015-10-22 04:46:14 +00:00
Richard Smith e87aeb378d When pretty-printing a C++11 literal operator, don't insert whitespace between
the "" and the suffix; that breaks names such as 'operator""if'. For symmetry,
also remove the space between the 'operator' and the '""'.

llvm-svn: 249641
2015-10-08 00:17:59 +00:00
Nathan Wilson e23a9a4514 Modify DeclaratorChuck::getFunction to be passed an Exception Specification SourceRange
Summary:
- Store the exception specification range's begin and end SourceLocation in DeclaratorChuck::FunctionTypeInfo. These SourceLocations can be used in a FixItHint Range.
- Add diagnostic; function concept having an exception specification.


Reviewers: hubert.reinterpretcast, fraggamuffin, faisalv, aaron.ballman, rsmith

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D11789

llvm-svn: 246005
2015-08-26 04:19:36 +00:00
Douglas Gregor 9bda6cff20 C++ support for Objective-C lightweight generics.
Teach C++'s tentative parsing to handle specializations of Objective-C
class types (e.g., NSArray<NSString *>) as well as Objective-C
protocol qualifiers (id<NSCopying>) by extending type-annotation
tokens to handle this case. As part of this, remove Objective-C
protocol qualifiers from the declaration specifiers, which never
really made sense: instead, provide Sema entry points to make them
part of the type annotation token. Among other things, this properly
diagnoses bogus types such as "<NSCopying> id" which should have been
written as "id <NSCopying>".

Implements template instantiation support for, e.g., NSArray<T>*
in C++. Note that parameterized classes are not templates in the C++
sense, so that cannot (for example) be used as a template argument for
a template template parameter. Part of rdar://problem/6294649.

llvm-svn: 241545
2015-07-07 03:58:14 +00:00
Meador Inge f0af05c4a5 [Parse] Allow 'constexpr' in condition declarations
This patch implements the functionality specified by DR948.
The changes are two fold.  First, the parser was modified
to allow 'constexpr's to appear in condition declarations
(which was a hard error before).  Second, Sema was modified
to cleanup maybe odr-used declarations by way of a call to
'ActOnFinishFullExpr'.  As 'constexpr's were not allowed in
condition declarations before the cleanup wasn't necessary
(such declarations were always odr-used).

This fixes PR22491.

Differential Revision: http://reviews.llvm.org/D8978

llvm-svn: 240707
2015-06-25 22:06:40 +00:00
Daniel Marjamaki e59f8d7f1d [clang] Refactoring of conditions so they use isOneOf() instead of multiple is().
llvm-svn: 240008
2015-06-18 10:59:26 +00:00
Aaron Ballman 068aa51dae Refactored some common functionality into MaybeParseMicrosoftDeclSpecs; NFC.
llvm-svn: 237835
2015-05-20 20:58:33 +00:00
Benjamin Kramer 3012e59bc7 [Parse] Don't crash on ~A::{
Found by clang-fuzz.

llvm-svn: 233492
2015-03-29 14:35:39 +00:00
Benjamin Kramer d503c1c531 Make Token a real POD type.
We copy them around a lot and skip construction in favor of startToken,
make the default construction trivial to reflect that.

llvm-svn: 231603
2015-03-08 18:11:59 +00:00
David Majnemer ced8bdf74a Sema: Parenthesized bound destructor member expressions can be called
We would wrongfully reject (a.~A)() in both the destructor and
pseudo-destructor cases.

This fixes PR22668.

llvm-svn: 230512
2015-02-25 17:36:15 +00:00
Nico Weber c60aa71aa2 For variables with dependent type, don't crash on `var->::new` or `var->__super`
ParsePostfixExpressionSuffix() for '->' (or '.') postfixes first calls
ActOnStartCXXMemberReference() to inform sema that a member reference is about
to start, and that function lets the parser know if sema thinks that the
base expression's type could allow a pseudo destructor from a semantic point of
view (for example, if the the base expression has a dependent type).

ParsePostfixExpressionSuffix() then calls ParseOptionalCXXScopeSpecifier() and
passes MayBePseudoDestructor on to that function, expecting the function to
set it to false if a pseudo destructor is impossible from a syntactic point of
view (due to a lack of '~' sigil).  However, ParseOptionalCXXScopeSpecifier()
had early-outs for ::new and __super, so MayBePseudoDestructor stayed true,
so we tried to parse a pseudo dtor, and then became confused since we couldn't
find a '~'.  Move the snippet in ParseOptionalCXXScopeSpecifier() that sets
MayBePseudoDestructor to false above the early exits.

Parts of this found by SLi's bot.

llvm-svn: 229449
2015-02-16 22:32:46 +00:00
Nico Weber 01a46adada Wrap to 80 columns. No behavior change.
llvm-svn: 229282
2015-02-15 06:15:40 +00:00
Richard Smith 215f423ff2 Add a warning for direct-list-initialization of a variable with a deduced type
(or of a lambda init-capture, which is sort-of such a variable). The semantics
of such constructs will change when we implement N3922, so we intend to warn on
this in Clang 3.6 then change the semantics in Clang 3.7.

llvm-svn: 228792
2015-02-11 02:41:33 +00:00
David Majnemer bda8632f9b Parse: Handle __declspec in a lambda definition
llvm-svn: 228121
2015-02-04 08:22:46 +00:00
Nico Weber 7f8ec52067 Follow-up to r217302: Don't crash on ~A::A in a postfix expr suffix followed by '<'.
This used to crash, complaining "ObjectType and scope specifier cannot coexist":

    struct A { } b = b.~A::A <int>;

The only other caller of ParseOptionalCXXScopeSpecifier() that passes in a
non-empty ObjectType clears the ObjectType of the scope specifier comes back
non-empty (see the tok::period case in Parser::ParsePostfixExpressionSuffix()),
so do that here too.

Found by SLi's bot.

llvm-svn: 227781
2015-02-02 05:33:50 +00:00
Nico Weber 10d02b5604 Remove a comment I accidentally added in r227581. No behavior change.
llvm-svn: 227777
2015-02-02 04:18:38 +00:00
Nico Weber f9e37be2d6 Follow-up to r217302 and r227555: Don't crash on inline ~A::A() if A is an int.
Even with r227555, this still crashed:

  struct S {
    int A;
    ~A::A() {}
  };

That's because ParseOptionalCXXScopeSpecifier()'s call to
ActOnCXXNestedNameSpecifier() doesn't mark the scope spec as invalid if sema
thought it's a good idea to fixit-correct "::" to ":".  For the diagnostic
improvement done in r217302, we never want :: to be interpreted as :, so fix
this by setting ColonSacred to false temporarily.

Found by SLi's bot.

llvm-svn: 227581
2015-01-30 16:53:11 +00:00
Nico Weber d004586faa Follow-up to r217302: Don't crash on ~A::A() if A is undeclared.
llvm-svn: 227555
2015-01-30 04:05:15 +00:00
Francisco Lopes da Silva 975a9f6ece Initial support for C++ parameter completion
The improved completion in call context now works with:

 - Functions.
 - Member functions.
 - Constructors.
 - New expressions.
 - Function call expressions.
 - Template variants of the previous.

There are still rough edges to be fixed:

 - Provide support for optional parameters.         (fix known)
 - Provide support for member initializers.         (fix known)
 - Provide support for variadic template functions. (fix unknown)
 - Others?

llvm-svn: 226670
2015-01-21 16:24:11 +00:00
Richard Smith 64e033f9c4 Fix crash-on-invalid and name lookup when recovering from ~X::X() typo.
llvm-svn: 226067
2015-01-15 00:48:52 +00:00
David Majnemer 234b8188df Parse: It's cleaner to handle cxx_defaultarg_end in SkipUntil directly
llvm-svn: 225616
2015-01-12 03:36:37 +00:00
David Majnemer 89296ee2c3 Parse: Don't parse beyond the end of the synthetic default argument tok
Recovery from malformed lambda introducers would find us consuming the
synthetic default argument token, which is bad.  Instead, stop right
before that token.

llvm-svn: 225613
2015-01-12 02:28:16 +00:00
David Majnemer e01c466c67 Parse: Don't crash when trailing return type is missing
Sema::CheckParmsForFunctionDef can't cope with a null TypeSourceInfo.
Don't let the AST contain the malformed lambda.

This fixes PR22122.

llvm-svn: 225505
2015-01-09 05:10:55 +00:00
David Majnemer ec3f49dfdf Fix build breakage
That's what I get for last second changes...

llvm-svn: 224967
2014-12-29 23:24:27 +00:00
David Majnemer f58efd9514 Parse: Recover more gracefully from extra :: tokens before a {
Instead of crashing, recover by eating the extra trailing scope
qualifier.  This means we will treat 'struct A:: {' as 'struct A {'.

llvm-svn: 224966
2014-12-29 23:12:23 +00:00
David Majnemer e8fb28fa0b Parse: Ignore '::' in 'struct :: {'
Let's pretend that we didn't see the '::' instead of go on believing
that we've got some anonymous, but globally qualified, struct.

llvm-svn: 224945
2014-12-29 19:19:18 +00:00
David Majnemer 6ca445e0dd Parse: Consume tokens more carefully in CheckForLParenAfterColonColon
We would consume the lparen even if it wasn't followed by an identifier
or a star-identifier pair.

This fixes PR21815.

llvm-svn: 224403
2014-12-17 01:39:22 +00:00
Kaelyn Takata b16e632c64 Wire up delayed typo correction to DiagnoseEmptyLookup and set up
Sema::ActOnIdExpression to use the new functionality.

Among other things, this allows recovery in several cases where it
wasn't possible before (e.g. correcting a mistyped static_cast<>).

llvm-svn: 222464
2014-11-20 22:06:40 +00:00
Richard Smith 0b3a46247e PR21437, final part of DR1330: delay-parsing of exception-specifications. This
is a re-commit of Doug's r154844 (modernized and updated to fit into current
Clang).

llvm-svn: 221918
2014-11-13 20:01:57 +00:00
Craig Topper a2c5153edd Remove the last couple uses of the ExprArg(just Expr*) typedef in Parser.
llvm-svn: 220897
2014-10-30 05:30:05 +00:00
Hal Finkel 23a0739161 Add RestrictQualifierLoc to DeclaratorChunk::FunctionTypeInfo
Clang supports __restrict__ as a function qualifier, but
DeclaratorChunk::FunctionTypeInfo lacked a field to track the qualifier's
source location (as we do with volatile, etc.). This was the subject of a FIXME
in GetFullTypeForDeclarator (in SemaType.cpp). This should also prove useful as
we add more warnings regarding questionable uses of the restrict qualifier.

There is no significant functional change (except for an improved source range
associated with the err_invalid_qualified_function_type diagnostic fixit
generated by GetFullTypeForDeclarator).

llvm-svn: 220215
2014-10-20 17:32:04 +00:00
Richard Smith a9d100178c PR20991: ::decltype is not valid.
llvm-svn: 219043
2014-10-04 01:57:39 +00:00
Nikola Smiljanic 67860249e0 -ms-extensions: Implement __super scope specifier (PR13236).
We build a NestedNameSpecifier that records the CXXRecordDecl in which
__super appeared. Name lookup is performed in all base classes of the
recorded CXXRecordDecl. Use of __super is allowed only inside class and
member function scope.

llvm-svn: 218484
2014-09-26 00:28:20 +00:00
Richard Smith efa6f736e6 Add error, recovery and fixit for "~A::A() {...}".
llvm-svn: 217302
2014-09-06 02:06:12 +00:00
Nico Weber 61281faa45 Wrap to 80 columns, no functionality change.
llvm-svn: 214036
2014-07-26 22:15:25 +00:00
Richard Smith 5a477c5e37 PR19751: (T())++ is not a cast-expression.
llvm-svn: 213022
2014-07-15 00:11:48 +00:00
Craig Topper 9d5583ef0a Convert StringLiteralParser constructor to use ArrayRef instead of a pointer and count.
llvm-svn: 211763
2014-06-26 04:58:39 +00:00
Nikola Smiljanic 01a7598561 Refactoring. Remove release and take methods from ActionResult. Rename takeAs to getAs.
llvm-svn: 209800
2014-05-29 10:55:11 +00:00
Craig Topper 161e4db52f [C++11] Use 'nullptr'. Parser edition.
llvm-svn: 209275
2014-05-21 06:02:52 +00:00
Richard Smith aba8b36abf Replace completely bogus ambiguous-compound-literal-in-C++ code with something
that isn't always wrong.

llvm-svn: 208844
2014-05-15 02:51:15 +00:00
Richard Smith 87e11a426d PR19748: Make sure we don't lose colon protection after the parenthesized type-id in a cast-expression.
llvm-svn: 208843
2014-05-15 02:43:47 +00:00
Alp Toker 1c583cc668 Cut off parsing early during code completion
These calls to ConsumeCodeCompletionToken() caused parsing to continue
needlessly when an immediate cutOffParsing() would do.

Document the function to clarify its correct usage.

llvm-svn: 207823
2014-05-02 03:43:14 +00:00
Serge Pavlov 6a7ffbed8a Improve error recovery around colon.
Parse of nested name spacifier is modified so that it properly recovers
if colon is mistyped as double colon in case statement.
This patch fixes PR15133.

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

llvm-svn: 206135
2014-04-13 16:52:03 +00:00
Richard Smith 9e2f0a4f62 PR19339: Disambiguate lambdas with init-captures from designated initializers
properly.

llvm-svn: 206128
2014-04-13 04:31:48 +00:00
Aaron Ballman e8d69b7fc9 Allow GNU-style attributes on lambda expressions.
llvm-svn: 203628
2014-03-12 00:01:07 +00:00
Aaron Ballman b5c59f5862 Gracefully handle an attribute specifier following a lambda introducer when the parameter list wasn't present.
llvm-svn: 203565
2014-03-11 13:03:15 +00:00
Chandler Carruth 757fcd6d1f [cleanup] Re-sort includes with llvm/utils/sort_includes.py and fix
a missing include from CLog.h.

CLog.h referenced most of the core libclang types but never directly
included Index.h that provides them. Previously it got lucky and other
headers were always included first but with the sorting it ended up
first in one case and stopped compiling. Adding the Index.h include
fixes it right up.

llvm-svn: 202810
2014-03-04 10:05:20 +00:00