r183879 - When copy-initializing a temporary for a reference binding, don't allow use of

Richard Smith richard-llvm at metafoo.co.uk
Wed Jun 12 17:57:58 PDT 2013


Author: rsmith
Date: Wed Jun 12 19:57:57 2013
New Revision: 183879

URL: http://llvm.org/viewvc/llvm-project?rev=183879&view=rev
Log:
When copy-initializing a temporary for a reference binding, don't allow use of
explicit constructors.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/references.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=183879&r1=183878&r2=183879&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jun 12 19:57:57 2013
@@ -3792,19 +3792,17 @@ static void TryReferenceInitializationCo
 
   //      - Otherwise, a temporary of type "cv1 T1" is created and initialized
   //        from the initializer expression using the rules for a non-reference
-  //        copy initialization (8.5). The reference is then bound to the
+  //        copy-initialization (8.5). The reference is then bound to the
   //        temporary. [...]
 
-  // Determine whether we are allowed to call explicit constructors or
-  // explicit conversion operators.
-  bool AllowExplicit = Kind.AllowExplicit();
-
   InitializedEntity TempEntity = InitializedEntity::InitializeTemporary(cv1T1);
 
+  // FIXME: Why do we use an implicit conversion here rather than trying
+  // copy-initialization?
   ImplicitConversionSequence ICS
     = S.TryImplicitConversion(Initializer, TempEntity.getType(),
-                              /*SuppressUserConversions*/ false,
-                              AllowExplicit,
+                              /*SuppressUserConversions=*/false,
+                              /*AllowExplicit=*/false,
                               /*FIXME:InOverloadResolution=*/false,
                               /*CStyle=*/Kind.isCStyleOrFunctionalCast(),
                               /*AllowObjCWritebackConversion=*/false);

Modified: cfe/trunk/test/SemaCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/references.cpp?rev=183879&r1=183878&r2=183879&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/references.cpp (original)
+++ cfe/trunk/test/SemaCXX/references.cpp Wed Jun 12 19:57:57 2013
@@ -137,3 +137,10 @@ namespace PR8608 {
 
 // The following crashed trying to recursively evaluate the LValue.
 const int &do_not_crash = do_not_crash; // expected-warning{{reference 'do_not_crash' is not yet bound to a value when used within its own initialization}}
+
+namespace ExplicitRefInit {
+  // This is invalid: we can't copy-initialize an 'A' temporary using an
+  // explicit constructor.
+  struct A { explicit A(int); };
+  const A &a(0); // expected-error {{reference to type 'const ExplicitRefInit::A' could not bind to an rvalue of type 'int'}}
+}





More information about the cfe-commits mailing list