[cfe-commits] r47005 - in /cfe/trunk: AST/ASTContext.cpp test/Sema/conditional-expr.c

Eli Friedman eli.friedman at gmail.com
Tue Feb 12 00:46:18 PST 2008


Author: efriedma
Date: Tue Feb 12 02:46:17 2008
New Revision: 47005

URL: http://llvm.org/viewvc/llvm-project?rev=47005&view=rev
Log:
Make typechecking for enum+int compatibility stricter.

Modified:
    cfe/trunk/AST/ASTContext.cpp
    cfe/trunk/test/Sema/conditional-expr.c

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=47005&r1=47004&r2=47005&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Tue Feb 12 02:46:17 2008
@@ -1709,10 +1709,14 @@
       
     // 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;
   }

Modified: cfe/trunk/test/Sema/conditional-expr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/conditional-expr.c?rev=47005&r1=47004&r2=47005&view=diff

==============================================================================
--- cfe/trunk/test/Sema/conditional-expr.c (original)
+++ cfe/trunk/test/Sema/conditional-expr.c Tue Feb 12 02:46:17 2008
@@ -27,5 +27,9 @@
   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}}
 }
 





More information about the cfe-commits mailing list