r351595 - [Sema] Suppress a warning about a forward-declared fixed enum in C mode
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 18 13:33:23 PST 2019
Author: epilk
Date: Fri Jan 18 13:33:23 2019
New Revision: 351595
URL: http://llvm.org/viewvc/llvm-project?rev=351595&view=rev
Log:
[Sema] Suppress a warning about a forward-declared fixed enum in C mode
As of r343360, we support fixed-enums in C. This lead to some
warnings in project headers where a fixed enum is forward declared
then later defined. In C++, this is fine, the forward declaration is
treated as a complete type even though the definition isn't present.
We use this rule in C too, but still warn about the forward
declaration anyways. This patch suppresses the warning.
rdar://problem/47356469
Differential revision: https://reviews.llvm.org/D56879
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/fixed-enum.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=351595&r1=351594&r2=351595&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 18 13:33:23 2019
@@ -14747,8 +14747,7 @@ CreateNewDecl:
// If this is an undefined enum, warn.
if (TUK != TUK_Definition && !Invalid) {
TagDecl *Def;
- if (IsFixed && (getLangOpts().CPlusPlus11 || getLangOpts().ObjC) &&
- cast<EnumDecl>(New)->isFixed()) {
+ if (IsFixed && cast<EnumDecl>(New)->isFixed()) {
// C++0x: 7.2p2: opaque-enum-declaration.
// Conflicts are diagnosed above. Do nothing.
}
Modified: cfe/trunk/test/Sema/fixed-enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/fixed-enum.c?rev=351595&r1=351594&r2=351595&view=diff
==============================================================================
--- cfe/trunk/test/Sema/fixed-enum.c (original)
+++ cfe/trunk/test/Sema/fixed-enum.c Fri Jan 18 13:33:23 2019
@@ -2,6 +2,7 @@
// RUN: %clang_cc1 -Weverything -xc++ -std=c++03 -DCXX03 -verify %s
// RUN: %clang_cc1 -Weverything -xobjective-c -DOBJC -verify %s
// RUN: %clang_cc1 -Weverything -std=c11 -xc -DC11 -verify %s
+// RUN: %clang_cc1 -pedantic -std=c11 -xc -DC11 -verify %s
// RUN: %clang_cc1 -Weverything -std=c11 -xc -fms-extensions -DMS -verify %s
enum X : int {e};
@@ -10,9 +11,29 @@ enum X : int {e};
#elif defined(CXX03)
// expected-warning at -4{{enumeration types with a fixed underlying type are a C++11 extension}}
#elif defined(OBJC)
-// expected-no-diagnostics
+// No diagnostic
#elif defined(C11)
// expected-warning at -8{{enumeration types with a fixed underlying type are a Clang extension}}
#elif defined(MS)
// expected-warning at -10{{enumeration types with a fixed underlying type are a Microsoft extension}}
#endif
+
+// Don't warn about the forward declaration in any language mode.
+enum Fwd : int;
+enum Fwd : int { e2 };
+#ifndef OBJC
+// expected-warning at -3 {{enumeration types with a fixed underlying type}}
+// expected-warning at -3 {{enumeration types with a fixed underlying type}}
+#endif
+
+// Always error on the incompatible redeclaration.
+enum BadFwd : int;
+#ifndef OBJC
+// expected-warning at -2 {{enumeration types with a fixed underlying type}}
+#endif
+// expected-note at -4 {{previous declaration is here}}
+enum BadFwd : char { e3 };
+#ifndef OBJC
+// expected-warning at -2 {{enumeration types with a fixed underlying type}}
+#endif
+// expected-error at -4 {{enumeration redeclared with different underlying type 'char' (was 'int')}}
More information about the cfe-commits
mailing list