Author: Timm Baeder Date: 2026-06-04T14:13:01+02:00 New Revision: 03127a03860b9d8cb440fe8f51c00647f45eb8be
URL: https://github.com/llvm/llvm-project/commit/03127a03860b9d8cb440fe8f51c00647f45eb8be DIFF: https://github.com/llvm/llvm-project/commit/03127a03860b9d8cb440fe8f51c00647f45eb8be.diff LOG: [clang][bytecode] Fix a diagnostic difference with extern variables (#201369) If the extern variable is constexpr of of non-array type, we should diagnose it as missing an initializer. Otherwise, we diagose a read of non-constexpr variable. Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/extern.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 72e4e2c20b243..e3a455ef7eb3c 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -154,6 +154,7 @@ static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC, if (const auto *VarD = dyn_cast<VarDecl>(VD); VarD && VarD->getType().isConstQualified() && + (VarD->isConstexpr() || !VarD->getType()->isArrayType()) && !VarD->getAnyInitializer()) { diagnoseMissingInitializer(S, OpPC, VD); return; diff --git a/clang/test/AST/ByteCode/extern.cpp b/clang/test/AST/ByteCode/extern.cpp index c3215931d41f8..bb2a367d0fcf4 100644 --- a/clang/test/AST/ByteCode/extern.cpp +++ b/clang/test/AST/ByteCode/extern.cpp @@ -1,8 +1,6 @@ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected %s // RUN: %clang_cc1 -verify=both,ref %s -// both-no-diagnostics - extern const double Num; extern const double Num = 12; @@ -13,3 +11,8 @@ constexpr int getE() { const int E = 10; static_assert(getE() == 10); + +extern const int carr[]; // both-note {{declared here}} +constexpr int n = carr[0]; // both-error {{must be initialized by a constant expression}} \ + // both-note {{read of non-constexpr variable}} + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
