]> granicus.if.org Git - clang/commitdiff
Fix a bug with struct initializers (in Sema::CheckInitializerListTypes()).
authorSteve Naroff <snaroff@apple.com>
Mon, 28 Jan 2008 02:00:41 +0000 (02:00 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 28 Jan 2008 02:00:41 +0000 (02:00 +0000)
Test case included from bz1948 (thanks Neil!).
Also fixed an 80 column violation...

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46430 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaDecl.cpp
test/Sema/array-init.c

index e674582eb0b658da8c56be70e55a8826de8534b7..8719ad7992bbc67840adbedff11d2c7044669c23 100644 (file)
@@ -461,8 +461,9 @@ bool Sema::CheckInitializerListTypes(InitListExpr*& IList, QualType &DeclType,
     }
   } else if (DeclType->isAggregateType() || DeclType->isUnionType()) {
     if (DeclType->isStructureType() || DeclType->isUnionType()) {
-      if (startIndex < IList->getNumInits() &&
-          Context.typesAreCompatible(IList->getInit(startIndex)->getType(), DeclType)) {
+      if (startIndex < IList->getNumInits() && !topLevel &&
+          Context.typesAreCompatible(IList->getInit(startIndex)->getType(), 
+                                     DeclType)) {
         // We found a compatible struct; per the standard, this initializes the
         // struct.  (The C standard technically says that this only applies for
         // initializers for declarations with automatic scope; however, this
index 4b94ed18cd20eff171be0589c3235b2187ccb639..cfbc2b926aef81b0be4047f72432f7ab17fa3099 100644 (file)
@@ -190,6 +190,11 @@ struct s2 {struct s1 c;} t2 = { t1 };
 struct s1 t3[] = {t1, t1, "abc", 0}; //expected-warning{{incompatible pointer to integer conversion initializing 'char *', expected 'char'}}
 int t4[sizeof t3 == 6 ? 1 : -1];
 }
+struct foo { int z; } w;
+int bar (void) { 
+  struct foo z = { w }; //expected-error{{incompatible type initializing 'struct foo', expected 'int'}}
+  return z.z; 
+} 
 struct s3 {void (*a)(void);} t5 = {autoStructTest};
 // GCC extension; flexible array init. Once this is implemented, the warning should be removed.
 // Note that clang objc implementation depends on this extension.