diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-02-09 00:50:06 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-02-09 00:50:06 +0000 |
commit | 2c79281ef66cb5001f0ebadf6b317250c21a1c01 (patch) | |
tree | 665f9c90214f7ef16ef9e3b57cd87049281731fc | |
parent | de09096a9ee7f670dc74c6a5b7771953ffaf5c62 (diff) |
Be more careful when checking initializer lists that involve reference
types; we don't want to give an expression reference type. Fixes PR6177.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95635 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaInit.cpp | 6 | ||||
-rw-r--r-- | test/SemaCXX/decl-init-ref.cpp | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index f536701ec2..3e710cfd5a 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -510,8 +510,8 @@ void InitListChecker::CheckExplicitInitList(const InitializedEntity &Entity, StructuredList->setSyntacticForm(IList); CheckListElementTypes(Entity, IList, T, /*SubobjectIsDesignatorContext=*/true, Index, StructuredList, StructuredIndex, TopLevelObject); - IList->setType(T); - StructuredList->setType(T); + IList->setType(T.getNonReferenceType()); + StructuredList->setType(T.getNonReferenceType()); if (hadError) return; @@ -1672,7 +1672,7 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index, = new (SemaRef.Context) InitListExpr(InitRange.getBegin(), 0, 0, InitRange.getEnd()); - Result->setType(CurrentObjectType); + Result->setType(CurrentObjectType.getNonReferenceType()); // Pre-allocate storage for the structured initializer list. unsigned NumElements = 0; diff --git a/test/SemaCXX/decl-init-ref.cpp b/test/SemaCXX/decl-init-ref.cpp index 656f3436a0..e1c7711530 100644 --- a/test/SemaCXX/decl-init-ref.cpp +++ b/test/SemaCXX/decl-init-ref.cpp @@ -24,3 +24,6 @@ int main() { const A& rca = f(); // expected-error {{reference initialization of type 'struct A const &' with initializer of type 'class B' is ambiguous}} A& ra = f(); // expected-error {{non-const lvalue reference to type 'struct A' cannot bind to a temporary of type 'class B'}} } + +struct PR6177 { A (&x)[1]; }; +PR6177 x = {{A()}}; // expected-error{{non-const lvalue reference to type 'struct A [1]' cannot bind to a temporary of type 'struct A'}} |