[cfe-commits] r90500 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/enum.cpp

John McCall rjmccall at apple.com
Thu Dec 3 16:07:04 PST 2009


Author: rjmccall
Date: Thu Dec  3 18:07:04 2009
New Revision: 90500

URL: http://llvm.org/viewvc/llvm-project?rev=90500&view=rev
Log:
When recovering from an invalid forward reference to an enum type in C++,
create the enum type in the same scope as you would a record type.


Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/enum.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=90500&r1=90499&r2=90500&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Dec  3 18:07:04 2009
@@ -4617,8 +4617,7 @@
         Previous.clear();
       }
     }
-  } else if (TUK == TUK_Reference && SS.isEmpty() && Name &&
-             (Kind != TagDecl::TK_enum || !getLangOptions().CPlusPlus)) {
+  } else if (TUK == TUK_Reference && SS.isEmpty() && Name) {
     // C++ [basic.scope.pdecl]p5:
     //   -- for an elaborated-type-specifier of the form
     //
@@ -4636,6 +4635,11 @@
     // C99 6.7.2.3p8 has a similar (but not identical!) provision for
     // C structs and unions.
     //
+    // It is an error in C++ to declare (rather than define) an enum
+    // type, including via an elaborated type specifier.  We'll
+    // diagnose that later; for now, declare the enum in the same
+    // scope as we would have picked for any other tag type.
+    //
     // GNU C also supports this behavior as part of its incomplete
     // enum types extension, while GNU C++ does not.
     //

Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=90500&r1=90499&r2=90500&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Thu Dec  3 18:07:04 2009
@@ -25,13 +25,13 @@
 
 /// PR3688
 struct s1 {
-  enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}} expected-note{{forward declaration of 'enum s1::e1'}}
+  enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}}
 };
 
 enum e1 { YES, NO };
 
 static enum e1 badfunc(struct s1 *q) {
-  return q->bar(); // expected-error{{calling function with incomplete return type 'enum s1::e1'}}
+  return q->bar();
 }
 
 enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}





More information about the cfe-commits mailing list