diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 7da711ed485db1..ef579bc5d8972a 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -468,7 +468,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) { // Possibly diagnose casts to enum types if the target type does not // have a fixed size. - if (CE->getType()->isEnumeralType()) { + if (Ctx.getLangOpts().CPlusPlus && CE->getType()->isEnumeralType()) { if (const auto *ET = CE->getType().getCanonicalType()->getAs(); ET && !ET->getDecl()->isFixed()) { if (!this->emitCheckEnumValue(*FromT, ET->getDecl(), CE)) diff --git a/clang/test/Sema/switch.c b/clang/test/Sema/switch.c index 69b34f96820d37..6e912d02d6cc75 100644 --- a/clang/test/Sema/switch.c +++ b/clang/test/Sema/switch.c @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum -Wcovered-switch-default -triple x86_64-linux-gnu %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wswitch-enum -Wcovered-switch-default -triple x86_64-linux-gnu %s -fexperimental-new-constant-interpreter void f (int z) { while (z) { default: z--; // expected-error {{statement not in switch}}