When type-checking a C++ "new" expression, don't type-check the actual 
initialization if any of the constructor/initialization arguments are
type-dependent. Fixes PR5224.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84365 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index d56c426..b6dcd76 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -418,6 +418,7 @@
   FunctionDecl *OperatorDelete = 0;
   Expr **PlaceArgs = (Expr**)PlacementArgs.get();
   unsigned NumPlaceArgs = PlacementArgs.size();
+    
   if (!AllocType->isDependentType() &&
       !Expr::hasAnyTypeDependentArguments(PlaceArgs, NumPlaceArgs) &&
       FindAllocationFunctions(StartLoc,
@@ -448,7 +449,9 @@
   Expr **ConsArgs = (Expr**)ConstructorArgs.get();
   const RecordType *RT;
   unsigned NumConsArgs = ConstructorArgs.size();
-  if (AllocType->isDependentType()) {
+  
+  if (AllocType->isDependentType() || 
+      Expr::hasAnyTypeDependentArguments(ConsArgs, NumConsArgs)) {
     // Skip all the checks.
   } else if ((RT = AllocType->getAs<RecordType>()) &&
              !AllocType->isAggregateType()) {
@@ -491,7 +494,7 @@
   }
 
   // FIXME: Also check that the destructor is accessible. (C++ 5.3.4p16)
-
+  
   PlacementArgs.release();
   ConstructorArgs.release();
   ArraySizeE.release();
diff --git a/test/SemaTemplate/fun-template-def.cpp b/test/SemaTemplate/fun-template-def.cpp
index dee4250..4d8aaa8 100644
--- a/test/SemaTemplate/fun-template-def.cpp
+++ b/test/SemaTemplate/fun-template-def.cpp
@@ -35,7 +35,7 @@
     dynamic_cast<U>(const_cast<T>(i1)))));
 
   new U(i1, t1);
-  new int(t1, u1); // expected-error {{initializer of a builtin type can only take one argument}}
+  new int(t1, u1);
   new (t1, u1) int;
   delete t1;
 
diff --git a/test/SemaTemplate/instantiate-expr-2.cpp b/test/SemaTemplate/instantiate-expr-2.cpp
index 146e63c..194593a 100644
--- a/test/SemaTemplate/instantiate-expr-2.cpp
+++ b/test/SemaTemplate/instantiate-expr-2.cpp
@@ -178,3 +178,18 @@
   
   template class A<int>;
 }
+
+namespace N12 {
+  // PR5224
+  template<typename T>
+  struct A { typedef int t0; };
+  
+  struct C  {
+    C(int);
+    
+    template<typename T>
+    static C *f0(T a0) {return new C((typename A<T>::t0) 1);   }
+  };
+
+  void f0(int **a) { C::f0(a); }
+}