]> granicus.if.org Git - clang/commitdiff
When type-checking a C++ "new" expression, don't type-check the actual
authorDouglas Gregor <dgregor@apple.com>
Sat, 17 Oct 2009 21:40:42 +0000 (21:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 17 Oct 2009 21:40:42 +0000 (21:40 +0000)
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

lib/Sema/SemaExprCXX.cpp
test/SemaTemplate/fun-template-def.cpp
test/SemaTemplate/instantiate-expr-2.cpp

index d56c426d00ab7c6e30da6a59499a96343ff5c8c8..b6dcd76d462906112b7343b07a50136cf58de907 100644 (file)
@@ -418,6 +418,7 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
   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 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
   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 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal,
   }
 
   // FIXME: Also check that the destructor is accessible. (C++ 5.3.4p16)
-
+  
   PlacementArgs.release();
   ConstructorArgs.release();
   ArraySizeE.release();
index dee4250078985664d27cd27d7f829b5aaf4e69c2..4d8aaa8d16f1e50d609d95e28b180425b8c6aa35 100644 (file)
@@ -35,7 +35,7 @@ T f1(T t1, U u1, int i1)
     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;
 
index 146e63c5bb00c46589aba95cc19ba546b95cedf1..194593ac4006e66e3a55ffa90afe993db67a5dca 100644 (file)
@@ -178,3 +178,18 @@ namespace N10 {
   
   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); }
+}