Skip to content

Commit a01788a

Browse files
tbaederryuxuanchen1997
authored andcommitted
[clang][Interp] Only diagnose out of bounds enum values in C++
1 parent 9dc657c commit a01788a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

clang/lib/AST/Interp/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
468468

469469
// Possibly diagnose casts to enum types if the target type does not
470470
// have a fixed size.
471-
if (CE->getType()->isEnumeralType()) {
471+
if (Ctx.getLangOpts().CPlusPlus && CE->getType()->isEnumeralType()) {
472472
if (const auto *ET = CE->getType().getCanonicalType()->getAs<EnumType>();
473473
ET && !ET->getDecl()->isFixed()) {
474474
if (!this->emitCheckEnumValue(*FromT, ET->getDecl(), CE))

clang/test/Sema/switch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum -Wcovered-switch-default -triple x86_64-linux-gnu %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum -Wcovered-switch-default -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter
23
void f (int z) {
34
while (z) {
45
default: z--; // expected-error {{statement not in switch}}

0 commit comments

Comments
 (0)