summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolodymyr Sapsai <vsapsai@apple.com>2017-09-21 17:41:30 +0000
committerVolodymyr Sapsai <vsapsai@apple.com>2017-09-21 17:41:30 +0000
commit8c9fde598b13bd8c35434a41e1afca929f053dd3 (patch)
treecf39b3cbf5daed2c8e695daa6867b83bbba56662
parent58f02afecd2d52620163ca4ffdf5943df7d35be1 (diff)
downloadbcm5719-llvm-8c9fde598b13bd8c35434a41e1afca929f053dd3.tar.gz
bcm5719-llvm-8c9fde598b13bd8c35434a41e1afca929f053dd3.zip
[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 llvm-svn: 313894
-rw-r--r--clang/lib/Sema/SemaDecl.cpp3
-rw-r--r--clang/test/Sema/enum.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 389cd7ab737..063a0b262b2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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;
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index cf59ca1feff..f9e40690c6a 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -125,9 +125,10 @@ enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
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
OpenPOWER on IntegriCloud