aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-03-06 18:34:03 +0000
committerDouglas Gregor <dgregor@apple.com>2009-03-06 18:34:03 +0000
commit80711a22fa06b734a68d719ac85d4e443a51cb09 (patch)
tree7d1ff807a14a0f0dada1ff41f3db62776c1ef9a1 /lib/Sema/SemaDecl.cpp
parent6370812b4277134b3c5cd143b20adc8c94890b91 (diff)
Implement the GNU semantics for forward declarations of enum types in
C and C++. Fixes PR3688. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66282 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 953e39f92d..f4c2788217 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2976,8 +2976,8 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
}
}
} else if (TK == TK_Reference && SS.isEmpty() && Name &&
- (Kind != TagDecl::TK_enum)) {
- // C++ [basic.scope.pdecl]p5:
+ (Kind != TagDecl::TK_enum || !getLangOptions().CPlusPlus)) {
+ // C.scope.pdecl]p5:
// -- for an elaborated-type-specifier of the form
//
// class-key identifier
@@ -2993,7 +2993,10 @@ Sema::DeclTy *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagKind TK,
//
// C99 6.7.2.3p8 has a similar (but not identical!) provision for
// C structs and unions.
-
+ //
+ // GNU C also supports this behavior as part of its incomplete
+ // enum types extension, while GNU C++ does not.
+ //
// Find the context where we'll be declaring the tag.
// FIXME: We would like to maintain the current DeclContext as the
// lexical context,
@@ -3027,7 +3030,11 @@ CreateNewDecl:
New = EnumDecl::Create(Context, SearchDC, Loc, Name,
cast_or_null<EnumDecl>(PrevDecl));
// If this is an undefined enum, warn.
- if (TK != TK_Definition) Diag(Loc, diag::ext_forward_ref_enum);
+ if (TK != TK_Definition && !Invalid) {
+ unsigned DK = getLangOptions().CPlusPlus? diag::err_forward_ref_enum
+ : diag::ext_forward_ref_enum;
+ Diag(Loc, DK);
+ }
} else {
// struct/union/class