From 5730f5ad03d5335cce9a8aaa208a9624265f2ce6 Mon Sep 17 00:00:00 2001 From: Volodymyr Sapsai Date: Tue, 22 Aug 2017 17:55:19 +0000 Subject: [PATCH] [Parser] Correct initalizer typos before lambda capture type is deduced. This is the same assertion as in https://reviews.llvm.org/D25206 that is triggered when RecordLayoutBuilder tries to compute the size of a field (for capture "typo_boo" in the test case) whose type hasn't been deduced. The fix is to add CorrectDelayedTyposInExpr call to the cases when we aren't disambiguating between an Obj-C message send and a lambda expression. rdar://problem/31760839 Reviewers: rsmith, ahatanak Reviewed By: arphaman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D36853 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311480 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseExprCXX.cpp | 2 ++ test/SemaCXX/cxx1y-init-captures.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index b95506294b..6ef747f402 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -966,6 +966,8 @@ Optional Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro, // that would be an error. ParsedType InitCaptureType; + if (!Init.isInvalid()) + Init = Actions.CorrectDelayedTyposInExpr(Init.get()); if (Init.isUsable()) { // Get the pointer and store it in an lvalue, so we can use it as an // out argument. diff --git a/test/SemaCXX/cxx1y-init-captures.cpp b/test/SemaCXX/cxx1y-init-captures.cpp index d681954707..4b82452ed5 100644 --- a/test/SemaCXX/cxx1y-init-captures.cpp +++ b/test/SemaCXX/cxx1y-init-captures.cpp @@ -206,3 +206,11 @@ void test(double weight) { find(weight); // expected-note {{in instantiation of function template specialization}} } } + +namespace init_capture_undeclared_identifier { + auto a = [x = y]{}; // expected-error{{use of undeclared identifier 'y'}} + + int typo_foo; // expected-note 2 {{'typo_foo' declared here}} + auto b = [x = typo_boo]{}; // expected-error{{use of undeclared identifier 'typo_boo'; did you mean 'typo_foo'}} + auto c = [x(typo_boo)]{}; // expected-error{{use of undeclared identifier 'typo_boo'; did you mean 'typo_foo'}} +} -- 2.40.0