[cfe-commits] r126184 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDecl.cpp test/SemaCXX/enum-scoped.cpp
Douglas Gregor
dgregor at apple.com
Mon Feb 21 18:55:24 PST 2011
Author: dgregor
Date: Mon Feb 21 20:55:24 2011
New Revision: 126184
URL: http://llvm.org/viewvc/llvm-project?rev=126184&view=rev
Log:
Fix a little bug in the handling of enumeration types with a fixed
underlying type: we weren't parsing unnamed enumeration types with a
fixed underlying type.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/test/SemaCXX/enum-scoped.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=126184&r1=126183&r2=126184&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon Feb 21 20:55:24 2011
@@ -57,6 +57,8 @@
"feature">;
def err_enumerator_list_missing_comma : Error<
"missing ',' between enumerators">;
+def err_enumerator_unnamed_no_def : Error<
+ "unnamed enumeration must be a definition">;
def ext_gnu_indirect_goto : Extension<
"use of GNU indirect-goto extension">, InGroup<GNU>;
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=126184&r1=126183&r2=126184&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Feb 21 20:55:24 2011
@@ -1975,6 +1975,7 @@
}
}
+ bool AllowFixedUnderlyingType = getLang().CPlusPlus0x;
bool IsScopedEnum = false;
bool IsScopedUsingClassTag = false;
@@ -1986,7 +1987,8 @@
}
// Must have either 'enum name' or 'enum {...}'.
- if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace)) {
+ if (Tok.isNot(tok::identifier) && Tok.isNot(tok::l_brace) &&
+ (AllowFixedUnderlyingType && Tok.isNot(tok::colon))) {
Diag(Tok, diag::err_expected_ident_lbrace);
// Skip the rest of this declarator, up until the comma or semicolon.
@@ -2013,7 +2015,7 @@
TypeResult BaseType;
// Parse the fixed underlying type.
- if (getLang().CPlusPlus0x && Tok.is(tok::colon)) {
+ if (AllowFixedUnderlyingType && Tok.is(tok::colon)) {
bool PossibleBitfield = false;
if (getCurScope()->getFlags() & Scope::ClassScope) {
// If we're in class scope, this can either be an enum declaration with
@@ -2092,6 +2094,14 @@
return;
}
+ if (!Name && TUK != Sema::TUK_Definition) {
+ Diag(Tok, diag::err_enumerator_unnamed_no_def);
+
+ // Skip the rest of this declarator, up until the comma or semicolon.
+ SkipUntil(tok::comma, true);
+ return;
+ }
+
bool Owned = false;
bool IsDependent = false;
SourceLocation TSTLoc = NameLoc.isValid()? NameLoc : StartLoc;
Modified: cfe/trunk/test/SemaCXX/enum-scoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-scoped.cpp?rev=126184&r1=126183&r2=126184&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum-scoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum-scoped.cpp Mon Feb 21 20:55:24 2011
@@ -96,3 +96,10 @@
enum class Redeclare7; // expected-note{{previous use is here}} expected-note{{previous use is here}}
enum class Redeclare7 : short; // expected-error{{redeclared with different underlying type}}
enum class Redeclare7 : short; // expected-error{{redeclared with different underlying type}}
+
+enum : long {
+ long_enum_val = 10000
+};
+
+enum : long x; // expected-error{{unnamed enumeration must be a definition}} \
+// expected-warning{{declaration does not declare anything}}
More information about the cfe-commits
mailing list