Skip to content

Commit

Permalink
[fixup][Sema] Allow in C to define tags inside enumerations.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vsapsai committed Sep 21, 2017
1 parent 58f02af commit 8c9fde5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Expand Up @@ -13916,7 +13916,8 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
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;
Expand Down
3 changes: 2 additions & 1 deletion clang/test/Sema/enum.c
Expand Up @@ -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
Expand Down

0 comments on commit 8c9fde5

Please sign in to comment.