PR20228: don't retain a pointer to a vector element after the container has been...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 23 Jul 2014 20:07:08 +0000 (20:07 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 23 Jul 2014 20:07:08 +0000 (20:07 +0000)
llvm-svn: 213790

clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

index 7fe5e7a..2745a8c 100644 (file)
@@ -3651,12 +3651,13 @@ static bool evaluateTypeTrait(Sema &S, TypeTrait Kind, SourceLocation KWLoc,
       if (T->isObjectType() || T->isFunctionType())
         T = S.Context.getRValueReferenceType(T);
       OpaqueArgExprs.push_back(
-        OpaqueValueExpr(Args[I]->getTypeLoc().getLocStart(), 
+        OpaqueValueExpr(Args[I]->getTypeLoc().getLocStart(),
                         T.getNonLValueExprType(S.Context),
                         Expr::getValueKindForType(T)));
-      ArgExprs.push_back(&OpaqueArgExprs.back());
     }
-    
+    for (Expr &E : OpaqueArgExprs)
+      ArgExprs.push_back(&E);
+
     // Perform the initialization in an unevaluated context within a SFINAE 
     // trap at translation unit scope.
     EnterExpressionEvaluationContext Unevaluated(S, Sema::Unevaluated);
index 3b94ef0..4833c14 100644 (file)
@@ -146,6 +146,10 @@ struct ThreeArgCtor {
   ThreeArgCtor(int*, char*, int);
 };
 
+struct VariadicCtor {
+  template<typename...T> VariadicCtor(T...);
+};
+
 void is_pod()
 {
   { int arr[T(__is_pod(int))]; }
@@ -1968,6 +1972,10 @@ void constructible_checks() {
   // PR19178
   { int arr[F(__is_constructible(Abstract))]; }
   { int arr[F(__is_nothrow_constructible(Abstract))]; }
+
+  // PR20228
+  { int arr[T(__is_constructible(VariadicCtor,
+                                 int, int, int, int, int, int, int, int, int))]; }
 }
 
 // Instantiation of __is_trivially_constructible