[cfe-commits] r95635 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/SemaCXX/decl-init-ref.cpp

Douglas Gregor dgregor at apple.com
Mon Feb 8 16:50:06 PST 2010


Author: dgregor
Date: Mon Feb  8 18:50:06 2010
New Revision: 95635

URL: http://llvm.org/viewvc/llvm-project?rev=95635&view=rev
Log:
Be more careful when checking initializer lists that involve reference
types; we don't want to give an expression reference type. Fixes PR6177.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/decl-init-ref.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=95635&r1=95634&r2=95635&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Mon Feb  8 18:50:06 2010
@@ -510,8 +510,8 @@
   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 @@
     = 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;

Modified: cfe/trunk/test/SemaCXX/decl-init-ref.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-init-ref.cpp?rev=95635&r1=95634&r2=95635&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/decl-init-ref.cpp (original)
+++ cfe/trunk/test/SemaCXX/decl-init-ref.cpp Mon Feb  8 18:50:06 2010
@@ -24,3 +24,6 @@
         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'}}





More information about the cfe-commits mailing list