summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-01-28 02:00:41 +0000
committerSteve Naroff <snaroff@apple.com>2008-01-28 02:00:41 +0000
commitaeb6b30f64ff48cd4a03e5a928d2824801dde174 (patch)
tree5fa9e5547b74e1ad85f52b91030e7988b5329cfd /clang
parent710b441174a8b065ef62c425228f4f6f0360134e (diff)
downloadbcm5719-llvm-aeb6b30f64ff48cd4a03e5a928d2824801dde174.tar.gz
bcm5719-llvm-aeb6b30f64ff48cd4a03e5a928d2824801dde174.zip
Fix a bug with struct initializers (in Sema::CheckInitializerListTypes()).
Test case included from bz1948 (thanks Neil!). Also fixed an 80 column violation... llvm-svn: 46430
Diffstat (limited to 'clang')
-rw-r--r--clang/Sema/SemaDecl.cpp5
-rw-r--r--clang/test/Sema/array-init.c5
2 files changed, 8 insertions, 2 deletions
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index e674582eb0b..8719ad7992b 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -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
diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c
index 4b94ed18cd2..cfbc2b926ae 100644
--- a/clang/test/Sema/array-init.c
+++ b/clang/test/Sema/array-init.c
@@ -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.
OpenPOWER on IntegriCloud