]> granicus.if.org Git - clang/commitdiff
[Sema] Don't crash when deduction fails for decltype(auto)
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 1 Jul 2015 00:29:28 +0000 (00:29 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 1 Jul 2015 00:29:28 +0000 (00:29 +0000)
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
test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp

index 02e59af558b23fb32268ad290dfd6af213aa3317..ae8157e70a603b38fc3d2de100cab0794d3c837d 100644 (file)
@@ -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);
index f7b3e8e7be6321db659743fff5dd0c35b7dc78f6..c3dc1de3ed6f1d969ae8f48c745b286e9819fe1f 100644 (file)
@@ -11,6 +11,9 @@ namespace std {
 int i;
 int &&f();
 
+template <typename T>
+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;