[cfe-commits] r66282 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDecl.cpp test/Sema/enum.c test/SemaCXX/enum.cpp
Douglas Gregor
dgregor at apple.com
Fri Mar 6 10:34:04 PST 2009
Author: dgregor
Date: Fri Mar 6 12:34:03 2009
New Revision: 66282
URL: http://llvm.org/viewvc/llvm-project?rev=66282&view=rev
Log:
Implement the GNU semantics for forward declarations of enum types in
C and C++. Fixes PR3688.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/enum.c
cfe/trunk/test/SemaCXX/enum.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=66282&r1=66281&r2=66282&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Fri Mar 6 12:34:03 2009
@@ -676,6 +676,8 @@
"use of %0 with tag type that does not match previous declaration")
DIAG(ext_forward_ref_enum, EXTENSION,
"ISO C forbids forward references to 'enum' types")
+DIAG(err_forward_ref_enum, ERROR,
+ "ISO C++ forbids forward references to 'enum' types")
DIAG(err_redefinition_of_enumerator, ERROR,
"redefinition of enumerator %0")
DIAG(err_duplicate_member, ERROR,
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66282&r1=66281&r2=66282&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Mar 6 12:34:03 2009
@@ -2976,8 +2976,8 @@
}
}
} 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 @@
//
// 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 @@
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
Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=66282&r1=66281&r2=66282&view=diff
==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Fri Mar 6 12:34:03 2009
@@ -73,3 +73,14 @@
enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
NYC1 = sizeof(enum NotYetComplete) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
};
+
+/// PR3688
+struct s1 {
+ enum e1 (*bar)(void); // expected-warning{{ISO C forbids forward references to 'enum' types}}
+};
+
+enum e1 { YES, NO };
+
+static enum e1 badfunc(struct s1 *q) {
+ return q->bar();
+}
Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=66282&r1=66281&r2=66282&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Fri Mar 6 12:34:03 2009
@@ -23,3 +23,18 @@
Foo myvar = A;
myvar = B;
}
+
+/// PR3688
+struct s1 {
+ 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) {
+ // FIXME: the message below should probably give context information
+ // in those types.
+ return q->bar(); // expected-error{{incompatible type returning 'enum e1', expected 'enum e1'}}
+}
+
+enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}}
More information about the cfe-commits
mailing list