[cfe-commits] r111512 - in /cfe/trunk: lib/AST/Type.cpp test/Sema/enum.c test/SemaCXX/enum.cpp

Eli Friedman eli.friedman at gmail.com
Wed Aug 18 21:39:37 PDT 2010


Author: efriedma
Date: Wed Aug 18 23:39:37 2010
New Revision: 111512

URL: http://llvm.org/viewvc/llvm-project?rev=111512&view=rev
Log:
Fix for PR7911 and PR7921: make isIntegralOrEnumerationType return false
for incomplete enum types.  An incomplete enum can't really be treated as
an "integral or enumeration" type, and the incorrect treatment leads to
bad behavior for many callers.

This makes isIntegralOrEnumerationType equivalent to isIntegerType; I think
we should globally replace the latter with the former; thoughts?


Modified:
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/test/Sema/enum.c
    cfe/trunk/test/SemaCXX/enum.cpp

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=111512&r1=111511&r2=111512&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Wed Aug 18 23:39:37 2010
@@ -460,10 +460,13 @@
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() >= BuiltinType::Bool &&
            BT->getKind() <= BuiltinType::Int128;
-  
-  if (isa<EnumType>(CanonicalType))
-    return true;
-  
+
+  // Check for a complete enum type; incomplete enum types are not properly an
+  // enumeration type in the sense required here.
+  if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
+    if (TT->getDecl()->isEnum() && TT->getDecl()->isDefinition())
+      return true;
+
   return false;  
 }
 

Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=111512&r1=111511&r2=111512&view=diff
==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Wed Aug 18 23:39:37 2010
@@ -96,3 +96,9 @@
 // PR4515
 enum PR4515 {PR4515a=1u,PR4515b=(PR4515a-2)/2};
 int CheckPR4515[PR4515b==0?1:-1];
+
+// PR7911
+extern enum PR7911T PR7911V; // expected-warning{{ISO C forbids forward references to 'enum' types}}
+void PR7911F() {
+  switch (PR7911V); // expected-error {{statement requires expression of integer type}}
+}

Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=111512&r1=111511&r2=111512&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Wed Aug 18 23:39:37 2010
@@ -85,3 +85,8 @@
 // PR7466
 enum { }; // expected-warning{{declaration does not declare anything}}
 typedef enum { }; // expected-warning{{typedef requires a name}}
+
+// PR7921
+enum PR7921E {
+    PR7921V = (PR7921E)(123) // expected-error {{expression is not an integer constant expression}}
+};





More information about the cfe-commits mailing list