Skip to content

Commit d45f1d0

Browse files
authored
[clang][bytecode] Fix self-init diagnostics in C++23 (#141044)
1 parent 34a55c9 commit d45f1d0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
670670
if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
671671
VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
672672

673-
if (!S.getLangOpts().CPlusPlus23 && VD == S.EvaluatingDecl) {
673+
if (VD == S.EvaluatingDecl &&
674+
!(S.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType())) {
674675
if (!S.getLangOpts().CPlusPlus14 &&
675676
!VD->getType().isConstant(S.getASTContext())) {
676677
// Diagnose as non-const read.

clang/test/AST/ByteCode/cxx23.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ constexpr int k(int n) {
7373
}
7474
constexpr int k0 = k(0);
7575

76+
#if __cplusplus >= 202302L
77+
constexpr int &b = b; // all-error {{must be initialized by a constant expression}} \
78+
// all-note {{initializer of 'b' is not a constant expression}} \
79+
// all-note {{declared here}}
80+
#endif
81+
7682
namespace StaticLambdas {
7783
constexpr auto static_capture_constexpr() {
7884
char n = 'n';

0 commit comments

Comments
 (0)