aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ByteCode/Interp.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-05-22 10:31:39 +0200
committerGitHub <noreply@github.com>2025-05-22 10:31:39 +0200
commit7cfeedf64addf6d20bdf47a669936ba6e46593d8 (patch)
tree9e56e330c6dc45e6b5809fb98c4f2fdb5d3d0962 /clang/lib/AST/ByteCode/Interp.cpp
parent466720960bd34532ecc342207ef4b81c98cae3c5 (diff)
downloadllvm-7cfeedf64addf6d20bdf47a669936ba6e46593d8.zip
llvm-7cfeedf64addf6d20bdf47a669936ba6e46593d8.tar.gz
llvm-7cfeedf64addf6d20bdf47a669936ba6e46593d8.tar.bz2
[clang][bytecode] Change diagnostics for self-initialization (#141006)
Change the diagnostics when reading from the variable we're currently initializing do be the same as the one the current interpreter emits.
Diffstat (limited to 'clang/lib/AST/ByteCode/Interp.cpp')
-rw-r--r--clang/lib/AST/ByteCode/Interp.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index fc61de9..b3ac84c 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -669,6 +669,21 @@ 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 (!S.getLangOpts().CPlusPlus14 &&
+ !VD->getType().isConstant(S.getASTContext())) {
+ // Diagnose as non-const read.
+ diagnoseNonConstVariable(S, OpPC, VD);
+ } else {
+ const SourceInfo &Loc = S.Current->getSource(OpPC);
+ // Diagnose as "read of object outside its lifetime".
+ S.FFDiag(Loc, diag::note_constexpr_access_uninit)
+ << AK << /*IsIndeterminate=*/false;
+ }
+ return false;
+ }
+
if (VD->getAnyInitializer()) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;