]> granicus.if.org Git - clang/commitdiff
Fix for PR7911 and PR7921: make isIntegralOrEnumerationType return false
authorEli Friedman <eli.friedman@gmail.com>
Thu, 19 Aug 2010 04:39:37 +0000 (04:39 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 19 Aug 2010 04:39:37 +0000 (04:39 +0000)
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?

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111512 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Type.cpp
test/Sema/enum.c
test/SemaCXX/enum.cpp

index 4ab463699c8f6738f621c6025d4e791ea9ce95bf..c2fc69fd2d3aaf11f043bd6d5d4d117f84fe43c6 100644 (file)
@@ -460,10 +460,13 @@ bool Type::isIntegralOrEnumerationType() const {
   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;  
 }
 
index 057015011e8f6625ba95178d82f77e2ac3f16491..64aa31bc4b6f307e49357f2d4ba461b20ddba319 100644 (file)
@@ -96,3 +96,9 @@ char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer t
 // 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}}
+}
index 0690ead250859d9810266803fac965a3362e66c7..1dc55e39162bdbdcc8ed1449d7d5bdcc1c16c48d 100644 (file)
@@ -85,3 +85,8 @@ namespace PR7051 {
 // 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}}
+};