]> granicus.if.org Git - clang/commitdiff
[Sema] Do not permit binding a reference to a compound literal
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Apr 2015 07:35:03 +0000 (07:35 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Apr 2015 07:35:03 +0000 (07:35 +0000)
We could probably make this work if we cared enough.  However, we are
far outside any language rules at this point.

This fixes PR21834.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235818 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/cxx0x-initializer-references.cpp

index 3ee1a7f8ad4bf0bb932c19295654280d8499a2a0..eef9272cca1fbf3f97b9019ad80d79d50af593c1 100644 (file)
@@ -3438,6 +3438,11 @@ static void TryReferenceListInitialization(Sema &S,
     Sequence.SetFailed(InitializationSequence::FK_ReferenceBindingToInitList);
     return;
   }
+  // Can't reference initialize a compound literal.
+  if (Entity.getKind() == InitializedEntity::EK_CompoundLiteralInit) {
+    Sequence.SetFailed(InitializationSequence::FK_ReferenceBindingToInitList);
+    return;
+  }
 
   QualType DestType = Entity.getType();
   QualType cv1T1 = DestType->getAs<ReferenceType>()->getPointeeType();
index f9164fb1ae65c937ab70a6fb52dc92bbb1c19ee0..390047ea075214cde84e955ebe30db5e64a4f689 100644 (file)
@@ -125,3 +125,7 @@ namespace PR20844 {
   struct B { operator A&(); } b;
   A &a{b}; // expected-error {{excess elements}} expected-note {{in initialization of temporary of type 'PR20844::A'}}
 }
+
+namespace PR21834 {
+const int &a = (const int &){0}; // expected-error {{cannot bind to an initializer list}}
+}