diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-02-12 08:46:17 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-02-12 08:46:17 +0000 |
commit | a7bf7ed4768569c53f78e8e02f82d52f3daefbe4 (patch) | |
tree | 6f846d6f7760db82d3d96dc1e0d208ebb45bb03f | |
parent | 2b90b0d09e620ff2f8f02e42100ec32de9a94111 (diff) | |
download | bcm5719-llvm-a7bf7ed4768569c53f78e8e02f82d52f3daefbe4.tar.gz bcm5719-llvm-a7bf7ed4768569c53f78e8e02f82d52f3daefbe4.zip |
Make typechecking for enum+int compatibility stricter.
llvm-svn: 47005
-rw-r--r-- | clang/AST/ASTContext.cpp | 12 | ||||
-rw-r--r-- | clang/test/Sema/conditional-expr.c | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp index c00779c171b..d01de2b3a9c 100644 --- a/clang/AST/ASTContext.cpp +++ b/clang/AST/ASTContext.cpp @@ -1709,10 +1709,14 @@ bool ASTContext::typesAreCompatible(QualType lhs, QualType rhs) { // C99 6.7.2.2p4: Each enumerated type shall be compatible with char, // a signed integer type, or an unsigned integer type. - // FIXME: need to check the size and ensure it's the same. - if ((lcanon->isEnumeralType() && rcanon->isIntegralType()) || - (rcanon->isEnumeralType() && lcanon->isIntegralType())) - return true; + if (lcanon->isEnumeralType() && rcanon->isIntegralType()) { + EnumDecl* EDecl = cast<EnumDecl>(cast<TagType>(lcanon)->getDecl()); + return EDecl->getIntegerType() == rcanon; + } + if (rcanon->isEnumeralType() && lcanon->isIntegralType()) { + EnumDecl* EDecl = cast<EnumDecl>(cast<TagType>(rcanon)->getDecl()); + return EDecl->getIntegerType() == lcanon; + } return false; } diff --git a/clang/test/Sema/conditional-expr.c b/clang/test/Sema/conditional-expr.c index a24846ac1de..813aaee9d0d 100644 --- a/clang/test/Sema/conditional-expr.c +++ b/clang/test/Sema/conditional-expr.c @@ -27,5 +27,9 @@ void foo() { int (*pf)[2]; int (*pv)[i]; pf = (i ? pf : pv); + + enum {xxx,yyy,zzz} e, *ee; + short x; + ee = ee ? &x : ee ? &i : &e; // expected-warning {{pointer type mismatch}} } |