From 59ae3c854240108b28a0b3cb0aa1e9fb4c90e5ff Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 16 Dec 2009 16:54:16 +0000 Subject: [PATCH] In Sema::CheckInitializerTypes, replace a use of CheckReferenceInit with an InitializationSequence llvm-svn: 91542 --- clang/lib/Sema/SemaInit.cpp | 16 +++++++++++----- clang/test/SemaCXX/decl-init-ref.cpp | 2 +- .../instantiate-template-template-parm.cpp | 2 +- clang/test/SemaTemplate/metafun-apply.cpp | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 04506908f07b..20008a7c1cd5 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -192,11 +192,17 @@ bool Sema::CheckInitializerTypes(Expr *&Init, QualType &DeclType, // A variable declared to be a T& or T&&, that is "reference to type T" // (8.3.2), shall be initialized by an object, or function, of // type T or by an object that can be converted into a T. - if (DeclType->isReferenceType()) - return CheckReferenceInit(Init, DeclType, InitLoc, - /*SuppressUserConversions=*/false, - /*AllowExplicit=*/DirectInit, - /*ForceRValue=*/false); + if (DeclType->isReferenceType()) { + InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1); + OwningExprResult CurInit = InitSeq.Perform(*this, Entity, Kind, + MultiExprArg(*this, (void**)&Init, 1), + &DeclType); + if (CurInit.isInvalid()) + return true; + + Init = CurInit.takeAs(); + return false; + } // C99 6.7.8p3: The type of the entity to be initialized shall be an array // of unknown size ("[]") or an object type that is not a variable array type. diff --git a/clang/test/SemaCXX/decl-init-ref.cpp b/clang/test/SemaCXX/decl-init-ref.cpp index ab743694a18d..4200b169abee 100644 --- a/clang/test/SemaCXX/decl-init-ref.cpp +++ b/clang/test/SemaCXX/decl-init-ref.cpp @@ -18,7 +18,7 @@ class B : public BASE , public BASE1 extern B f(); -const int& ri = (void)0; // expected-error {{invalid initialization of reference of type 'int const &' from expression of type 'void'}} +const int& ri = (void)0; // expected-error {{reference to type 'int const' could not bind to an rvalue of type 'void'}} int main() { const A& rca = f(); // expected-error {{conversion from 'class B' to 'struct A const' is ambiguous}} diff --git a/clang/test/SemaTemplate/instantiate-template-template-parm.cpp b/clang/test/SemaTemplate/instantiate-template-template-parm.cpp index 6035308b0a9f..f48a0c7a7145 100644 --- a/clang/test/SemaTemplate/instantiate-template-template-parm.cpp +++ b/clang/test/SemaTemplate/instantiate-template-template-parm.cpp @@ -17,7 +17,7 @@ struct add_reference { int i; apply::type ip = &i; apply::type ir = i; -apply::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot be initialized with a value of type 'int'}} +apply::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}} // Template template parameters template struct B; // expected-note{{has a different type 'int'}} diff --git a/clang/test/SemaTemplate/metafun-apply.cpp b/clang/test/SemaTemplate/metafun-apply.cpp index 56a2dc9c392e..4044d14a84ef 100644 --- a/clang/test/SemaTemplate/metafun-apply.cpp +++ b/clang/test/SemaTemplate/metafun-apply.cpp @@ -29,7 +29,7 @@ struct apply1 { int i; apply1::type ip = &i; apply1::type ir = i; -apply1::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot be initialized with a value of type 'int'}} +apply1::type fr = i; // expected-error{{non-const lvalue reference to type 'float' cannot bind to a value of unrelated type 'int'}} void test() { apply1::type t; // expected-note{{in instantiation of template class 'struct apply1' requested here}} \