[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313894 91177308-0d34-0410-b5e6-96231b3b80d8
(cherry picked from commit 3069e68753f8bbcd7abcdf2596895b97fa87c43e)
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index bf8238c..856ddf6 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -13941,7 +13941,8 @@
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;
diff --git a/test/Sema/enum.c b/test/Sema/enum.c
index cf59ca1..f9e4069 100644
--- a/test/Sema/enum.c
+++ b/test/Sema/enum.c
@@ -125,9 +125,10 @@
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