[cfe-commits] r46430 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/array-init.c
Steve Naroff
snaroff at apple.com
Sun Jan 27 18:00:41 PST 2008
Author: snaroff
Date: Sun Jan 27 20:00:41 2008
New Revision: 46430
URL: http://llvm.org/viewvc/llvm-project?rev=46430&view=rev
Log:
Fix a bug with struct initializers (in Sema::CheckInitializerListTypes()).
Test case included from bz1948 (thanks Neil!).
Also fixed an 80 column violation...
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/array-init.c
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=46430&r1=46429&r2=46430&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Sun Jan 27 20:00:41 2008
@@ -461,8 +461,9 @@
}
} 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
Modified: cfe/trunk/test/Sema/array-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/array-init.c?rev=46430&r1=46429&r2=46430&view=diff
==============================================================================
--- cfe/trunk/test/Sema/array-init.c (original)
+++ cfe/trunk/test/Sema/array-init.c Sun Jan 27 20:00:41 2008
@@ -190,6 +190,11 @@
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.
More information about the cfe-commits
mailing list