diff options
author | John McCall <rjmccall@apple.com> | 2009-12-04 00:07:04 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-12-04 00:07:04 +0000 |
commit | 5023437f5a897d513c08ddf64b74d688252a23e5 (patch) | |
tree | be9673ad8f57e11909cd09cd8be6f1bc1cf60274 | |
parent | bcd7f9f8cb2f1b78e8ad991677a4364044e1deb7 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90500 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 8 | ||||
-rw-r--r-- | test/SemaCXX/enum.cpp | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e02849f5d5..3e29b726e8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4617,8 +4617,7 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, 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 @@ Sema::DeclPtrTy Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, // 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. // diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp index db256812ab..1aba107a69 100644 --- a/test/SemaCXX/enum.cpp +++ b/test/SemaCXX/enum.cpp @@ -25,13 +25,13 @@ void bar() { /// 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}} |