From: Douglas Gregor Date: Sun, 20 Dec 2009 22:01:25 +0000 (+0000) Subject: Switch default-initialization of variables of class type (or array thereof) over... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=745880f35066bdb1950d0e870608295221346fc5;p=clang Switch default-initialization of variables of class type (or array thereof) over to InitializationSequence. I could swear that this fixes a PR somewhere, but I couldn't figure out which one git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91796 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c873f39579..a80d62a473 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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())); FinalizeVarWithDestructor(Var, InitType); } } else { diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 44f6cf3d74..18164d685f 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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()) diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp index 7e87e576ca..6e7f80842e 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p15.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s struct NonDefaultConstructible { - NonDefaultConstructible(const NonDefaultConstructible&); + NonDefaultConstructible(const NonDefaultConstructible&); // expected-note{{candidate function}} }; template diff --git a/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp b/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp index 9e3401a1ae..3eaf89689a 100644 --- a/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp +++ b/test/CXX/temp/temp.spec/temp.expl.spec/p4.cpp @@ -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 diff --git a/test/CXX/temp/temp.spec/temp.explicit/p1.cpp b/test/CXX/temp/temp.spec/temp.explicit/p1.cpp index 718812be30..7c7ca6cf32 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p1.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p1.cpp @@ -48,8 +48,8 @@ template void X1::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 diff --git a/test/SemaCXX/constructor-recovery.cpp b/test/SemaCXX/constructor-recovery.cpp index 8e00620398..c1bb436283 100644 --- a/test/SemaCXX/constructor-recovery.cpp +++ b/test/SemaCXX/constructor-recovery.cpp @@ -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; } diff --git a/test/SemaCXX/default2.cpp b/test/SemaCXX/default2.cpp index 58f35dcec3..eda4be2919 100644 --- a/test/SemaCXX/default2.cpp +++ b/test/SemaCXX/default2.cpp @@ -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}} diff --git a/test/SemaCXX/deleted-function.cpp b/test/SemaCXX/deleted-function.cpp index 572ef34330..d9df1bf5b0 100644 --- a/test/SemaCXX/deleted-function.cpp +++ b/test/SemaCXX/deleted-function.cpp @@ -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}} diff --git a/test/SemaCXX/direct-initializer.cpp b/test/SemaCXX/direct-initializer.cpp index 0930ff798f..1a87a3edf3 100644 --- a/test/SemaCXX/direct-initializer.cpp +++ b/test/SemaCXX/direct-initializer.cpp @@ -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 { diff --git a/test/SemaTemplate/explicit-instantiation.cpp b/test/SemaTemplate/explicit-instantiation.cpp index 9c75cb7d61..fbb5edbefd 100644 --- a/test/SemaTemplate/explicit-instantiation.cpp +++ b/test/SemaTemplate/explicit-instantiation.cpp @@ -25,8 +25,8 @@ T X0::value; // expected-error{{no matching constructor}} template int X0::value; -struct NotDefaultConstructible { - NotDefaultConstructible(int); +struct NotDefaultConstructible { // expected-note{{candidate function}} + NotDefaultConstructible(int); // expected-note{{candidate function}} }; template NotDefaultConstructible X0::value; // expected-note{{instantiation}} diff --git a/test/SemaTemplate/instantiate-static-var.cpp b/test/SemaTemplate/instantiate-static-var.cpp index bd298fc63a..8a2f34d475 100644 --- a/test/SemaTemplate/instantiate-static-var.cpp +++ b/test/SemaTemplate/instantiate-static-var.cpp @@ -30,7 +30,7 @@ T Z::value; // expected-error{{no matching constructor}} struct DefCon {}; struct NoDefCon { - NoDefCon(const NoDefCon&); + NoDefCon(const NoDefCon&); // expected-note{{candidate function}} }; void test() {