From 1dc7490ad52b82b6c33b2300d0e582db80c25997 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 26 Apr 2015 07:35:03 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235818 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaInit.cpp | 5 +++++ test/SemaCXX/cxx0x-initializer-references.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 3ee1a7f8ad..eef9272cca 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -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()->getPointeeType(); diff --git a/test/SemaCXX/cxx0x-initializer-references.cpp b/test/SemaCXX/cxx0x-initializer-references.cpp index f9164fb1ae..390047ea07 100644 --- a/test/SemaCXX/cxx0x-initializer-references.cpp +++ b/test/SemaCXX/cxx0x-initializer-references.cpp @@ -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}} +} -- 2.50.1