From de2a93dd31e7590f7763432c253f75632980b9ed Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Tue, 17 Mar 2015 23:50:12 +0000 Subject: [PATCH] Fix a crash when the size of an 'auto' is needed and its initalizer contained a typo correction (the auto decl was being marked as dependent unnecessarily, which triggered an assertion in cases where the size of the type is needed). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232568 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 14 ++++++++++++++ test/SemaCXX/cxx11-crashes.cpp | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 32e3924e35..743c4ce4d1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8688,6 +8688,20 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, // C++11 [decl.spec.auto]p6. Deduce the type which 'auto' stands in for. if (TypeMayContainAuto && VDecl->getType()->isUndeducedType()) { + // Attempt typo correction early so that the type of the init expression can + // be deduced based on the chosen correction:if the original init contains a + // TypoExpr. + ExprResult Res = CorrectDelayedTyposInExpr(Init); + if (!Res.isUsable()) { + RealDecl->setInvalidDecl(); + return; + } + if (Res.get() != Init) { + Init = Res.get(); + if (CXXDirectInit) + CXXDirectInit = dyn_cast(Init); + } + Expr *DeduceInit = Init; // Initializer could be a C++ direct-initializer. Deduction only works if it // contains exactly one expression. diff --git a/test/SemaCXX/cxx11-crashes.cpp b/test/SemaCXX/cxx11-crashes.cpp index bd51af1da2..97c959454c 100644 --- a/test/SemaCXX/cxx11-crashes.cpp +++ b/test/SemaCXX/cxx11-crashes.cpp @@ -74,3 +74,20 @@ namespace b6981007 { } } } + +namespace incorrect_auto_type_deduction_for_typo { +struct S { + template S(T t) { + (void)sizeof(t); + (void)new auto(t); + } +}; + +void Foo(S); + +void test(int some_number) { // expected-note {{'some_number' declared here}} + auto x = sum_number; // expected-error {{use of undeclared identifier 'sum_number'; did you mean 'some_number'?}} + auto lambda = [x] {}; + Foo(lambda); +} +} -- 2.40.0