]> granicus.if.org Git - clang/commitdiff
Make typechecking for enum+int compatibility stricter.
authorEli Friedman <eli.friedman@gmail.com>
Tue, 12 Feb 2008 08:46:17 +0000 (08:46 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 12 Feb 2008 08:46:17 +0000 (08:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47005 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTContext.cpp
test/Sema/conditional-expr.c

index c00779c171be27ec165c75bab9bb8b2e8fb123e3..d01de2b3a9c878f35abede3551308c830fd95d28 100644 (file)
@@ -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;
   }
index a24846ac1de6718683736f01c7cdbc7d09f233b0..813aaee9d0d15fd8479102de56e75dc57737dd42 100644 (file)
@@ -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}}
 }