From: Eli Friedman Date: Tue, 22 Dec 2009 02:10:53 +0000 (+0000) Subject: Switch file-scope assignment initialization over to InitializationSequence. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a91eb541a6adf81acf872e7315bc6b814c3241eb;p=clang Switch file-scope assignment initialization over to InitializationSequence. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91881 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a179265130..f62d0aa6f9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3557,22 +3557,16 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { VDecl->setInvalidDecl(); } else if (!VDecl->isInvalidDecl()) { InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1); - if (InitSeq) { - OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind, + OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind, MultiExprArg(*this, (void**)&Init, 1), - &DclT); - if (Result.isInvalid()) { - VDecl->setInvalidDecl(); - return; - } - - Init = Result.takeAs(); - } else { - InitSeq.Diagnose(*this, Entity, Kind, &Init, 1); + &DclT); + if (Result.isInvalid()) { VDecl->setInvalidDecl(); return; } + Init = Result.takeAs(); + // C++ 3.6.2p2, allow dynamic initialization of static initializers. // Don't check invalid declarations to avoid emitting useless diagnostics. if (!getLangOptions().CPlusPlus && !VDecl->isInvalidDecl()) { @@ -3630,9 +3624,18 @@ void Sema::AddInitializerToDecl(DeclPtrTy dcl, ExprArg init, bool DirectInit) { } else if (VDecl->isFileVarDecl()) { if (VDecl->getStorageClass() == VarDecl::Extern) Diag(VDecl->getLocation(), diag::warn_extern_init); - if (!VDecl->isInvalidDecl()) - if (CheckInitializerTypes(Init, DclT, Entity, Kind)) + if (!VDecl->isInvalidDecl()) { + InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1); + OwningExprResult Result = InitSeq.Perform(*this, Entity, Kind, + MultiExprArg(*this, (void**)&Init, 1), + &DclT); + if (Result.isInvalid()) { VDecl->setInvalidDecl(); + return; + } + + Init = Result.takeAs(); + } // C++ 3.6.2p2, allow dynamic initialization of static initializers. // Don't check invalid declarations to avoid emitting useless diagnostics. diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 3ff2588356..c7a2769c44 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -3201,8 +3201,12 @@ InitializationSequence::Perform(Sema &S, return S.Owned((Expr *)0); QualType DestType = Entity.getType().getType().getNonReferenceType(); + // FIXME: Ugly hack around the fact that Entity.getType().getType() is not + // the same as Entity.getDecl()->getType() in cases involving type merging, + // and we want latter when it makes sense. if (ResultType) - *ResultType = Entity.getType().getType(); + *ResultType = Entity.getDecl() ? Entity.getDecl()->getType() : + Entity.getType().getType(); Sema::OwningExprResult CurInit = S.Owned((Expr *)0); diff --git a/test/CXX/temp/temp.spec/temp.explicit/p1.cpp b/test/CXX/temp/temp.spec/temp.explicit/p1.cpp index 7c7ca6cf32..626bdf1815 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p1.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p1.cpp @@ -68,7 +68,7 @@ struct X2 { }; template -T X2::static_member1 = 17; // expected-error{{incompatible type}} +T X2::static_member1 = 17; // expected-error{{cannot initialize}} template U X2::static_member2; // expected-error{{no matching}} diff --git a/test/CXX/temp/temp.spec/temp.explicit/p10.cpp b/test/CXX/temp/temp.spec/temp.explicit/p10.cpp index 9021fc2b46..290a874296 100644 --- a/test/CXX/temp/temp.spec/temp.explicit/p10.cpp +++ b/test/CXX/temp/temp.spec/temp.explicit/p10.cpp @@ -20,7 +20,7 @@ struct X0::Inner { }; template -T X0::static_var = 1; // expected-error{{incompatible type}} +T X0::static_var = 1; // expected-error{{cannot initialize}} extern template struct X0; template struct X0; // expected-note 2{{instantiation}} diff --git a/test/SemaCXX/addr-of-overloaded-function.cpp b/test/SemaCXX/addr-of-overloaded-function.cpp index 45a65f8199..3b06119393 100644 --- a/test/SemaCXX/addr-of-overloaded-function.cpp +++ b/test/SemaCXX/addr-of-overloaded-function.cpp @@ -9,7 +9,7 @@ int (*pfi)(int) = &f; // selects f(int) // FIXME: This error message is not very good. We need to keep better // track of what went wrong when the implicit conversion failed to // give a better error message here. -int (*pfe)(...) = &f; // expected-error{{incompatible type initializing '', expected 'int (*)(...)'}} +int (*pfe)(...) = &f; // expected-error{{cannot initialize a variable of type 'int (*)(...)' with an rvalue of type ''}} int (&rfi)(int) = f; // selects f(int) int (&rfd)(double) = f; // selects f(double) diff --git a/test/SemaCXX/aggregate-initialization.cpp b/test/SemaCXX/aggregate-initialization.cpp index cd801d78c2..255b352982 100644 --- a/test/SemaCXX/aggregate-initialization.cpp +++ b/test/SemaCXX/aggregate-initialization.cpp @@ -22,7 +22,7 @@ struct NonAggr4 { virtual void f(); }; -NonAggr1 na1 = { 17 }; // expected-error{{initialization of non-aggregate type 'struct NonAggr1' with an initializer list}} -NonAggr2 na2 = { 17 }; // expected-error{{initialization of non-aggregate type 'struct NonAggr2' with an initializer list}} -NonAggr3 na3 = { 17 }; // expected-error{{initialization of non-aggregate type 'class NonAggr3' with an initializer list}} -NonAggr4 na4 = { 17 }; // expected-error{{initialization of non-aggregate type 'struct NonAggr4' with an initializer list}} +NonAggr1 na1 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr1' cannot be initialized with an initializer list}} +NonAggr2 na2 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr2' cannot be initialized with an initializer list}} +NonAggr3 na3 = { 17 }; // expected-error{{non-aggregate type 'class NonAggr3' cannot be initialized with an initializer list}} +NonAggr4 na4 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr4' cannot be initialized with an initializer list}} diff --git a/test/SemaCXX/dcl_init_aggr.cpp b/test/SemaCXX/dcl_init_aggr.cpp index 98aa7218f5..87b51e32e5 100644 --- a/test/SemaCXX/dcl_init_aggr.cpp +++ b/test/SemaCXX/dcl_init_aggr.cpp @@ -13,7 +13,7 @@ struct NonAggregate { int a, b; }; -NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{initialization of non-aggregate type 'struct NonAggregate' with an initializer list}} +NonAggregate non_aggregate_test = { 1, 2 }; // expected-error{{non-aggregate type 'struct NonAggregate' cannot be initialized with an initializer list}} NonAggregate non_aggregate_test2[2] = { { 1, 2 }, { 3, 4 } }; // expected-error 2 {{initialization of non-aggregate type 'struct NonAggregate' with an initializer list}} diff --git a/test/SemaTemplate/typename-specifier-2.cpp b/test/SemaTemplate/typename-specifier-2.cpp index 2a21f727df..551cac3168 100644 --- a/test/SemaTemplate/typename-specifier-2.cpp +++ b/test/SemaTemplate/typename-specifier-2.cpp @@ -18,7 +18,7 @@ int i; // 'aka' telling us that we're dealing with an int**. Should we fix // getDesugaredType to dig through pointers and such? bind_metafun::type::type ip = &i; -bind_metafun::type::type fp = &i; // expected-error{{incompatible type initializing 'int *', expected 'bind_metafun::type::type' (aka 'float *')}} +bind_metafun::type::type fp = &i; // expected-error{{cannot initialize a variable of type 'bind_metafun::type::type' (aka 'float *') with an rvalue of type 'int *'}} template