From 87821a35a3f66a9ae43da9da78505b520b062e2d Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 1 Jul 2015 00:29:28 +0000 Subject: [PATCH] [Sema] Don't crash when deduction fails for decltype(auto) We didn't check the return result of BuildDecltypeType, resulting in us crashing when we tried to grab the canonical version of the type. This fixes PR23995. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241131 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateDeduction.cpp | 2 ++ test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index 02e59af558..ae8157e70a 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -3968,6 +3968,8 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *&Init, QualType &Result) { } QualType Deduced = BuildDecltypeType(Init, Init->getLocStart(), false); + if (Deduced.isNull()) + return DAR_FailedAlreadyDiagnosed; // FIXME: Support a non-canonical deduced type for 'auto'. Deduced = Context.getCanonicalType(Deduced); Result = SubstituteAutoTransform(*this, Deduced).Apply(Type); diff --git a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp index f7b3e8e7be..c3dc1de3ed 100644 --- a/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp +++ b/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp @@ -11,6 +11,9 @@ namespace std { int i; int &&f(); +template +void overloaded_fn(T); // expected-note {{possible target}} + using Int = int; using IntLRef = int&; using IntRRef = int&&; @@ -57,6 +60,7 @@ decltype(auto) ((((((v1)))))) = 0; // ok decltype(auto) v2[1] = { 0 }; // expected-error {{cannot form array of 'decltype(auto)'}} decltype(auto) &v3 = { 0 }; // expected-error {{cannot form reference to 'decltype(auto)'}} decltype(auto) *v4 = { 0 }; // expected-error {{cannot form pointer to 'decltype(auto)'}} +decltype(auto) v5 = &overloaded_fn; // expected-error {{could not be resolved}} auto multi1a = 0, &multi1b = multi1a; auto multi1c = multi1a, multi1d = multi1b; -- 2.50.1