r313894 - [fixup][Sema] Allow in C to define tags inside enumerations.
Volodymyr Sapsai via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 21 10:41:30 PDT 2017
Author: vsapsai
Date: Thu Sep 21 10:41:30 2017
New Revision: 313894
URL: http://llvm.org/viewvc/llvm-project?rev=313894&view=rev
Log:
[fixup][Sema] Allow in C to define tags inside enumerations.
Fix for too aggressive error err_type_defined_in_enum introduced in
r313386. Defining tags inside enumerations is prohibited in C++ but
allowed in C.
Reviewers: aaron.ballman, rnk, doug.gregor
Reviewed By: rnk
Subscribers: alberto_magni, cfe-commits
Differential Revision: https://reviews.llvm.org/D38109
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/enum.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=313894&r1=313893&r2=313894&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 21 10:41:30 2017
@@ -13916,7 +13916,8 @@ CreateNewDecl:
Invalid = true;
}
- if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
+ if (!Invalid && getLangOpts().CPlusPlus && TUK == TUK_Definition &&
+ DC->getDeclKind() == Decl::Enum) {
Diag(New->getLocation(), diag::err_type_defined_in_enum)
<< Context.getTagDeclType(New);
Invalid = true;
Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=313894&r1=313893&r2=313894&view=diff
==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Thu Sep 21 10:41:30 2017
@@ -125,9 +125,10 @@ enum Color { Red, Green, Blue }; // expe
typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}
// PR28903
+// In C it is valid to define tags inside enums.
struct PR28903 {
enum {
- PR28903_A = (enum { // expected-error-re {{'enum PR28903::(anonymous at {{.*}})' cannot be defined in an enumeration}}
+ PR28903_A = (enum {
PR28903_B,
PR28903_C = PR28903_B
})0
More information about the cfe-commits
mailing list