r337585 - Prevent Scoped Enums from being Integral constant expressions:
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 20 10:42:09 PDT 2018
Author: erichkeane
Date: Fri Jul 20 10:42:09 2018
New Revision: 337585
URL: http://llvm.org/viewvc/llvm-project?rev=337585&view=rev
Log:
Prevent Scoped Enums from being Integral constant expressions:
Discovered because of: https://bugs.llvm.org/show_bug.cgi?id=38235
It seems to me that a scoped enum should NOT be an integral constant expression
without a cast, so this seems like a sensical change.
Attributes that check for an integer parameter simply use this function to
ensure that they have an integer, so it was previously allowing a scoped enum.
Also added a test based on Richard's feedback to ensure that case labels still work.
Differential Revision: https://reviews.llvm.org/D49599
Added:
cfe/trunk/test/SemaCXX/PR38235.cpp
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=337585&r1=337584&r2=337585&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Jul 20 10:42:09 2018
@@ -11142,7 +11142,7 @@ static bool EvaluateCPlusPlus11IntegralC
const Expr *E,
llvm::APSInt *Value,
SourceLocation *Loc) {
- if (!E->getType()->isIntegralOrEnumerationType()) {
+ if (!E->getType()->isIntegralOrUnscopedEnumerationType()) {
if (Loc) *Loc = E->getExprLoc();
return false;
}
Added: cfe/trunk/test/SemaCXX/PR38235.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR38235.cpp?rev=337585&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR38235.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR38235.cpp Fri Jul 20 10:42:09 2018
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+enum class E { Foo, Bar = 97119 };
+
+void f() __attribute__((constructor(E::Foo))); // expected-error{{'constructor' attribute requires an integer constant}}
+void f2() __attribute__((constructor(E::Bar)));// expected-error{{'constructor' attribute requires an integer constant}}
+
+void switch_me(E e) {
+ switch (e) {
+ case E::Foo:
+ case E::Bar:
+ break;
+ }
+}
More information about the cfe-commits
mailing list