]> granicus.if.org Git - clang/commitdiff
[Parser] Correct typo after lambda capture initializer is parsed.
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 20 Dec 2016 02:11:29 +0000 (02:11 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 20 Dec 2016 02:11:29 +0000 (02:11 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290156 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseExprCXX.cpp
test/SemaCXX/lambda-expressions.cpp

index 3f335747a4ae95684663370b706a77cd8cda6d2e..ca1b3b1ad01bbe379be6f808bb9a315094bc2cd4 100644 (file)
@@ -902,6 +902,8 @@ Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
           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.
index 4d06fdf089572f3c38e2e29325687f32d7eb37f3..e0ab15dc6327476b0a16da28140cae432b8f32fd 100644 (file)
@@ -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'?}}
+}
+}