]> granicus.if.org Git - clang/commitdiff
Switch default-initialization of variables of class type (or array thereof) over...
authorDouglas Gregor <dgregor@apple.com>
Sun, 20 Dec 2009 22:01:25 +0000 (22:01 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 20 Dec 2009 22:01:25 +0000 (22:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91796 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
lib/Sema/SemaInit.cpp
test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp
test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp
test/CXX/temp/temp.spec/temp.explicit/p1.cpp
test/SemaCXX/constructor-recovery.cpp
test/SemaCXX/default2.cpp
test/SemaCXX/deleted-function.cpp
test/SemaCXX/direct-initializer.cpp
test/SemaTemplate/explicit-instantiation.cpp
test/SemaTemplate/instantiate-static-var.cpp

index c873f3957979452bc28285c99de129e942f16c81..a80d62a473807de78abe0ed91dad104e835c9c0d 100644 (file)
@@ -3745,28 +3745,19 @@ void Sema::ActOnUninitializedDecl(DeclPtrTy dcl,
           InitType->isRecordType() && !InitType->isDependentType()) {
         if (!RequireCompleteType(Var->getLocation(), InitType,
                                  diag::err_invalid_incomplete_type_use)) {
-          ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(*this);
-
-          CXXConstructorDecl *Constructor
-            = PerformInitializationByConstructor(InitType, 
-                                                 MultiExprArg(*this, 0, 0),
-                                                 Var->getLocation(),
-                                               SourceRange(Var->getLocation(),
-                                                           Var->getLocation()),
-                                                 Var->getDeclName(),
-                         InitializationKind::CreateDefault(Var->getLocation()),
-                                                 ConstructorArgs);
-          
-          // FIXME: Location info for the variable initialization?
-          if (!Constructor)
+          InitializedEntity Entity
+            = InitializedEntity::InitializeVariable(Var);
+          InitializationKind Kind
+            = InitializationKind::CreateDefault(Var->getLocation());
+
+          InitializationSequence InitSeq(*this, Entity, Kind, 0, 0);
+          OwningExprResult Init = InitSeq.Perform(*this, Entity, Kind,
+                                                  MultiExprArg(*this, 0, 0));
+          if (Init.isInvalid())
             Var->setInvalidDecl();
           else {
-            // FIXME: Cope with initialization of arrays
-            if (!Constructor->isTrivial() &&
-                InitializeVarWithConstructor(Var, Constructor, 
-                                             move_arg(ConstructorArgs)))
-              Var->setInvalidDecl();
-            
+            Var->setInit(Context, 
+                       MaybeCreateCXXExprWithTemporaries(Init.takeAs<Expr>()));
             FinalizeVarWithDestructor(Var, InitType);
           }
         } else {
index 44f6cf3d74c0095327ccc9fd4624bcbf568d4c6d..18164d685f6f565912646da71ebd82afaeb0eaaa 100644 (file)
@@ -3391,7 +3391,8 @@ InitializationSequence::Perform(Sema &S,
         return S.ExprError();
           
       // Build the an expression that constructs a temporary.
-      CurInit = S.BuildCXXConstructExpr(Loc, Step->Type, Constructor, 
+      CurInit = S.BuildCXXConstructExpr(Loc, Entity.getType().getType(),
+                                        Constructor, 
                                         move_arg(ConstructorArgs),
                                         ConstructorInitRequiresZeroInit);
       if (CurInit.isInvalid())
index 7e87e576ca9c6f366a03757f402a10f1ae5908f5..6e7f80842ec043670cc598c9f7584235bf3a1f1a 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 struct NonDefaultConstructible {
-  NonDefaultConstructible(const NonDefaultConstructible&);
+  NonDefaultConstructible(const NonDefaultConstructible&); // expected-note{{candidate function}}
 };
 
 template<typename T, typename U>
index 9e3401a1aef969d9886f0c96f59d2ba606a67f85..3eaf89689a254e591eb5ef0be876ccb90e0713a9 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-struct IntHolder { // expected-note{{here}}
-  IntHolder(int);
+struct IntHolder { // expected-note{{here}} // expected-note 2{{candidate function}}
+  IntHolder(int); // expected-note 2{{candidate function}}
 };
 
 template<typename T, typename U>
index 718812be30a3a96982ee1f27063b5eaff665e16f..7c7ca6cf329db36b05386e141073cfa6a9fe9fcc 100644 (file)
@@ -48,8 +48,8 @@ template void X1<int>::f<>(int&, int*); // expected-note{{instantiation}}
 
 // Explicitly instantiate members of a class template
 struct Incomplete; // expected-note{{forward declaration}}
-struct NonDefaultConstructible {
-  NonDefaultConstructible(int);
+struct NonDefaultConstructible { // expected-note{{candidate function}}
+  NonDefaultConstructible(int); // expected-note{{candidate function}}
 };
 
 template<typename T, typename U>
index 8e00620398076f57961373078028744e3c5b13b3..c1bb43628356e87554e25909ba59d4a2e3df09f3 100644 (file)
@@ -1,10 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-struct C {  // expected-note {{candidate function}}
-  virtual C() = 0; // expected-error{{constructor cannot be declared 'virtual'}} \
-                      expected-note {{candidate function}}
+struct C {
+  virtual C() = 0; // expected-error{{constructor cannot be declared 'virtual'}}
 };
 
 void f() {
- C c;  // expected-error {{call to constructor of 'c' is ambiguous}}
+ C c;
 }
index 58f35dcec313c62558d9dcf9aa11b96eb62231d2..eda4be29192d6d01809da66a357b6eb08e21533a 100644 (file)
@@ -82,7 +82,7 @@ int Y::mem4(int i = a) // expected-error{{invalid use of nonstatic data member '
 // constructors.
 class Z {
 public:
-  Z(Z&, int i = 17); // expected-note 2 {{candidate function}}
+  Z(Z&, int i = 17); // expected-note 3 {{candidate function}}
 
   void f(Z& z) { 
     Z z2;    // expected-error{{no matching constructor for initialization}}
index 572ef34330998208e18c41fb1bdc8d0a7436bdfc..d9df1bf5b05ac011ff544f7d7d03a35223cd59eb 100644 (file)
@@ -16,7 +16,7 @@ void ov(int) {} // expected-note {{candidate function}}
 void ov(double) = delete; // expected-note {{candidate function has been explicitly deleted}}
 
 struct WithDel {
-  WithDel() = delete; // expected-note {{candidate function has been explicitly deleted}}
+  WithDel() = delete; // expected-note {{function has been explicitly marked deleted here}}
   void fn() = delete; // expected-note {{function has been explicitly marked deleted here}}
   operator int() = delete; // expected-note {{function has been explicitly marked deleted here}}
   void operator +(int) = delete;
@@ -29,7 +29,7 @@ void test() {
   ov(1);
   ov(1.0); // expected-error {{call to deleted function 'ov'}}
 
-  WithDel dd; // expected-error {{call to deleted constructor of 'dd'}}
+  WithDel dd; // expected-error {{call to deleted constructor of 'struct WithDel'}}
   WithDel *d = 0;
   d->fn(); // expected-error {{attempt to use a deleted function}}
   int i = *d; // expected-error {{invokes a deleted function}}
index 0930ff798fba156c10a6022011c6808f3fb9ec58..1a87a3edf334d0be16a31007431f564d3df2a08e 100644 (file)
@@ -20,9 +20,9 @@ public:
   X(float, Y); // expected-note{{candidate function}}
 };
 
-class Z {
+class Z { // expected-note{{candidate function}}
 public:
-  Z(int);
+  Z(int); // expected-note{{candidate function}}
 };
 
 void g() {
@@ -32,7 +32,7 @@ void g() {
   Y y(1.0);
   X x4(3.14, y);
 
-  Z z; // expected-error{{no matching constructor for initialization of 'z'}}
+  Z z; // expected-error{{no matching constructor for initialization of 'class Z'}}
 }
 
 struct Base {
index 9c75cb7d610f7c09db592dd12becf4eae233d207..fbb5edbefd6c2b9907f30fb6820730fb41edce4c 100644 (file)
@@ -25,8 +25,8 @@ T X0<T>::value; // expected-error{{no matching constructor}}
 
 template int X0<int>::value;
 
-struct NotDefaultConstructible {
-  NotDefaultConstructible(int);
+struct NotDefaultConstructible { // expected-note{{candidate function}}
+  NotDefaultConstructible(int); // expected-note{{candidate function}}
 };
 
 template NotDefaultConstructible X0<NotDefaultConstructible>::value; // expected-note{{instantiation}}
index bd298fc63a8889e9256906508fd0765ac2ee46e7..8a2f34d475a76270fd4a463d6309399c49c2a894 100644 (file)
@@ -30,7 +30,7 @@ T Z<T>::value; // expected-error{{no matching constructor}}
 struct DefCon {};
 
 struct NoDefCon { 
-  NoDefCon(const NoDefCon&);
+  NoDefCon(const NoDefCon&); // expected-note{{candidate function}}
 };
 
 void test() {