[clang] d45f1d0 - [clang][bytecode] Fix self-init diagnostics in C++23 (#141044)
via cfe-commits
cfe-commits at lists.llvm.org
Thu May 22 05:26:55 PDT 2025
Author: Timm Baeder
Date: 2025-05-22T14:26:52+02:00
New Revision: d45f1d08272ead39700d54dc800ce78d97170bde
URL: https://github.com/llvm/llvm-project/commit/d45f1d08272ead39700d54dc800ce78d97170bde
DIFF: https://github.com/llvm/llvm-project/commit/d45f1d08272ead39700d54dc800ce78d97170bde.diff
LOG: [clang][bytecode] Fix self-init diagnostics in C++23 (#141044)
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/cxx23.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index b3ac84ce9278f..7cc0d2a526480 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -670,7 +670,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
- if (!S.getLangOpts().CPlusPlus23 && VD == S.EvaluatingDecl) {
+ if (VD == S.EvaluatingDecl &&
+ !(S.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType())) {
if (!S.getLangOpts().CPlusPlus14 &&
!VD->getType().isConstant(S.getASTContext())) {
// Diagnose as non-const read.
diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index ce18a9d473302..417d35dbca946 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -73,6 +73,12 @@ constexpr int k(int n) {
}
constexpr int k0 = k(0);
+#if __cplusplus >= 202302L
+constexpr int &b = b; // all-error {{must be initialized by a constant expression}} \
+ // all-note {{initializer of 'b' is not a constant expression}} \
+ // all-note {{declared here}}
+#endif
+
namespace StaticLambdas {
constexpr auto static_capture_constexpr() {
char n = 'n';
More information about the cfe-commits
mailing list