[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.

llvm-svn: 235818
This commit is contained in:
David Majnemer 2015-04-26 07:35:03 +00:00
parent b64b8e16db
commit 9370dc2fda
2 changed files with 9 additions and 0 deletions

View 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();

View 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}}
}