Author: Timm Bäder Date: 2024-07-19T16:06:49+02:00 New Revision: 9145ffa134ed57c25ec62879c1aeff50595d08be
URL: https://github.com/llvm/llvm-project/commit/9145ffa134ed57c25ec62879c1aeff50595d08be DIFF: https://github.com/llvm/llvm-project/commit/9145ffa134ed57c25ec62879c1aeff50595d08be.diff LOG: [clang][Interp] Only diagnose out of bounds enum values in C++ Added: Modified: clang/lib/AST/Interp/Compiler.cpp clang/test/Sema/switch.c Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Compiler.cpp b/clang/lib/AST/Interp/Compiler.cpp index 7da711ed485db..ef579bc5d8972 100644 --- a/clang/lib/AST/Interp/Compiler.cpp +++ b/clang/lib/AST/Interp/Compiler.cpp @@ -468,7 +468,7 @@ bool Compiler<Emitter>::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<EnumType>(); 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 69b34f96820d3..6e912d02d6cc7 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}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits