r235818 - [Sema] Do not permit binding a reference to a compound literal
David Majnemer
david.majnemer at gmail.com
Sun Apr 26 00:35:04 PDT 2015
Author: majnemer
Date: Sun Apr 26 02:35:03 2015
New Revision: 235818
URL: http://llvm.org/viewvc/llvm-project?rev=235818&view=rev
Log:
[Sema] Do not permit binding a reference to a compound literal
We could probably make this work if we cared enough. However, we are
far outside any language rules at this point.
This fixes PR21834.
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=235818&r1=235817&r2=235818&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sun Apr 26 02:35:03 2015
@@ -3438,6 +3438,11 @@ static void TryReferenceListInitializati
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();
Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp?rev=235818&r1=235817&r2=235818&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp Sun Apr 26 02:35:03 2015
@@ -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}}
+}
More information about the cfe-commits
mailing list