diff options
author | Erich Keane <erich.keane@intel.com> | 2018-07-20 17:42:09 +0000 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2018-07-20 17:42:09 +0000 |
commit | 1ddd4bf87f5d131ef2f4787fd732986bff6f2018 (patch) | |
tree | ff5019208928405eee92f926be81c8cd5002a6bb | |
parent | f435a7eada02567e315371f73e64eab26829a67b (diff) | |
download | bcm5719-llvm-1ddd4bf87f5d131ef2f4787fd732986bff6f2018.tar.gz bcm5719-llvm-1ddd4bf87f5d131ef2f4787fd732986bff6f2018.zip |
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
llvm-svn: 337585
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 2 | ||||
-rw-r--r-- | clang/test/SemaCXX/PR38235.cpp | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index bf21bc65e2b..e69914f25da 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -11142,7 +11142,7 @@ static bool EvaluateCPlusPlus11IntegralConstantExpr(const ASTContext &Ctx, const Expr *E, llvm::APSInt *Value, SourceLocation *Loc) { - if (!E->getType()->isIntegralOrEnumerationType()) { + if (!E->getType()->isIntegralOrUnscopedEnumerationType()) { if (Loc) *Loc = E->getExprLoc(); return false; } diff --git a/clang/test/SemaCXX/PR38235.cpp b/clang/test/SemaCXX/PR38235.cpp new file mode 100644 index 00000000000..11874c837bc --- /dev/null +++ b/clang/test/SemaCXX/PR38235.cpp @@ -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; + } +} |