r290156 - [Parser] Correct typo after lambda capture initializer is parsed.

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 19 18:11:30 PST 2016


Author: ahatanak
Date: Mon Dec 19 20:11:29 2016
New Revision: 290156

URL: http://llvm.org/viewvc/llvm-project?rev=290156&view=rev
Log:
[Parser] Correct typo after lambda capture initializer is parsed.

This patch fixes an assertion that is triggered when RecordLayoutBuilder
tries to compute the size of a field (for capture "name" in the test
case) whose type hasn't been deduced. The patch fixes the bug by
correcting the typo of the capture initializer after the initializer is
parsed and before setting the expression for the annotation token.

Fixes PR30566.

rdar://problem/23380132

Differential Revision: https://reviews.llvm.org/D25206

Modified:
    cfe/trunk/lib/Parse/ParseExprCXX.cpp
    cfe/trunk/test/SemaCXX/lambda-expressions.cpp

Modified: cfe/trunk/lib/Parse/ParseExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExprCXX.cpp?rev=290156&r1=290155&r2=290156&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExprCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExprCXX.cpp Mon Dec 19 20:11:29 2016
@@ -902,6 +902,8 @@ Optional<unsigned> Parser::ParseLambdaIn
           SourceLocation StartLoc = Tok.getLocation();
           InMessageExpressionRAIIObject MaybeInMessageExpression(*this, true);
           Init = ParseInitializer();
+          if (!Init.isInvalid())
+            Init = Actions.CorrectDelayedTyposInExpr(Init.get());
 
           if (Tok.getLocation() != StartLoc) {
             // Back out the lexing of the token after the initializer.

Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=290156&r1=290155&r2=290156&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original)
+++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Mon Dec 19 20:11:29 2016
@@ -558,3 +558,18 @@ int func() {
   decltype(a)::D b;
 }
 }
+
+namespace PR30566 {
+int name1; // expected-note {{'name1' declared here}}
+
+struct S1 {
+  template<class T>
+  S1(T t) { s = sizeof(t); }
+  int s;
+};
+
+void foo1() {
+  auto s0 = S1{[name=]() {}}; // expected-error 2 {{expected expression}}
+  auto s1 = S1{[name=name]() {}}; // expected-error {{use of undeclared identifier 'name'; did you mean 'name1'?}}
+}
+}




More information about the cfe-commits mailing list