[cfe-commits] r94329 - in /cfe/trunk: lib/Sema/SemaInit.cpp test/SemaCXX/aggregate-initialization.cpp test/SemaCXX/dcl_init_aggr.cpp test/SemaTemplate/instantiate-expr-4.cpp

Anders Carlsson andersca at mac.com
Sat Jan 23 12:20:40 PST 2010


Author: andersca
Date: Sat Jan 23 14:20:40 2010
New Revision: 94329

URL: http://llvm.org/viewvc/llvm-project?rev=94329&view=rev
Log:
Use the new init code for member subobjects.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
    cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp
    cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Sat Jan 23 14:20:40 2010
@@ -236,7 +236,8 @@
                        InitListExpr *IList, QualType DeclType, unsigned &Index,
                        InitListExpr *StructuredList,
                        unsigned &StructuredIndex);
-  void CheckStructUnionTypes(InitListExpr *IList, QualType DeclType,
+  void CheckStructUnionTypes(const InitializedEntity *Entity,
+                             InitListExpr *IList, QualType DeclType,
                              RecordDecl::field_iterator Field,
                              bool SubobjectIsDesignatorContext, unsigned &Index,
                              InitListExpr *StructuredList,
@@ -633,7 +634,7 @@
   } else if (DeclType->isAggregateType()) {
     if (DeclType->isRecordType()) {
       RecordDecl *RD = DeclType->getAs<RecordType>()->getDecl();
-      CheckStructUnionTypes(IList, DeclType, RD->field_begin(),
+      CheckStructUnionTypes(Entity, IList, DeclType, RD->field_begin(),
                             SubobjectIsDesignatorContext, Index,
                             StructuredList, StructuredIndex,
                             TopLevelObject);
@@ -1060,7 +1061,8 @@
   }
 }
 
-void InitListChecker::CheckStructUnionTypes(InitListExpr *IList,
+void InitListChecker::CheckStructUnionTypes(const InitializedEntity *Entity,
+                                            InitListExpr *IList,
                                             QualType DeclType,
                                             RecordDecl::field_iterator Field,
                                             bool SubobjectIsDesignatorContext,
@@ -1138,8 +1140,17 @@
       continue;
     }
 
-    CheckSubElementType(0, IList, Field->getType(), Index,
-                        StructuredList, StructuredIndex);
+    // FIXME: Once we know Entity is not null, we can get rid of the check
+    // and the else block.
+    if (Entity) {
+      InitializedEntity MemberEntity =
+        InitializedEntity::InitializeMember(*Field, Entity);
+      CheckSubElementType(&MemberEntity, IList, Field->getType(), Index,
+                          StructuredList, StructuredIndex);
+    } else {
+      CheckSubElementType(0, IList, Field->getType(), Index,
+                          StructuredList, StructuredIndex);
+    }
     InitializedSomething = true;
 
     if (DeclType->isUnionType()) {
@@ -1549,7 +1560,8 @@
 
     // Check the remaining fields within this class/struct/union subobject.
     bool prevHadError = hadError;
-    CheckStructUnionTypes(IList, CurrentObjectType, Field, false, Index,
+    
+    CheckStructUnionTypes(0, IList, CurrentObjectType, Field, false, Index,
                           StructuredList, FieldIndex);
     return hadError && !prevHadError;
   }

Modified: cfe/trunk/test/SemaCXX/aggregate-initialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/aggregate-initialization.cpp?rev=94329&r1=94328&r2=94329&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/aggregate-initialization.cpp (original)
+++ cfe/trunk/test/SemaCXX/aggregate-initialization.cpp Sat Jan 23 14:20:40 2010
@@ -37,3 +37,6 @@
 
 // Array initialization.
 int a[] = { (void *)1 }; // expected-error {{cannot initialize an array element of type 'int' with an rvalue of type 'void *'}}
+
+// Struct initialization.
+struct S { int a; } s = { (void *)1 }; // expected-error {{cannot initialize a member subobject of type 'int' with an rvalue of type 'void *'}}

Modified: cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp?rev=94329&r1=94328&r2=94329&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp (original)
+++ cfe/trunk/test/SemaCXX/dcl_init_aggr.cpp Sat Jan 23 14:20:40 2010
@@ -120,4 +120,4 @@
 u u2 = u1; 
 u u3 = 1; // expected-error{{no viable conversion}}
 u u4 = { 0, "asdf" };  // expected-error{{excess elements in union initializer}}
-u u5 = { "asdf" }; // expected-error{{incompatible type initializing 'char const [5]', expected 'int'}}
+u u5 = { "asdf" }; // expected-error{{cannot initialize a member subobject of type 'int' with an lvalue of type 'char const [5]'}}

Modified: cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp?rev=94329&r1=94328&r2=94329&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-expr-4.cpp Sat Jan 23 14:20:40 2010
@@ -197,7 +197,7 @@
 template<typename T, typename Val1, typename Val2>
 struct InitList2 {
   void f(Val1 val1, Val2 val2) { 
-    T x = { val1, val2 }; // expected-error{{incompatible}}
+    T x = { val1, val2 }; // expected-error{{cannot initialize}}
   }
 };
 





More information about the cfe-commits mailing list