[clang][bytecode] Don't diagnose const assignments...#192593
Merged
[clang][bytecode] Don't diagnose const assignments...#192593
Conversation
... when we're in CPCE mode.
Member
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes... when we're in CPCE mode. Full diff: https://github.com/llvm/llvm-project/pull/192593.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 17d194355208d..f5fb9f6b7bbfa 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -579,9 +579,11 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
if (llvm::is_contained(S.InitializingBlocks, Ptr.block()))
return true;
- const QualType Ty = Ptr.getType();
- const SourceInfo &Loc = S.Current->getSource(OpPC);
- S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
+ if (!S.checkingPotentialConstantExpression()) {
+ const QualType Ty = Ptr.getType();
+ const SourceInfo &Loc = S.Current->getSource(OpPC);
+ S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
+ }
return false;
}
diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp
index 4c4624d7505e2..43115416451ec 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -1345,3 +1345,12 @@ namespace ExpandOnOPTEPointers {
}
static_assert(test());
}
+
+namespace ConstIntPotentialConstantExpr {
+ /// NO error about a constexpr function that's never a constant expression.
+ constexpr int Const() {
+ const int a = 10; // both-note {{declared const here}}
+ a = 20; // both-error {{cannot assign to variable 'a' with const-qualified type 'const int'}}
+ return 1;
+ }
+}
|
alexfh
pushed a commit
to alexfh/llvm-project
that referenced
this pull request
Apr 18, 2026
... when we're in CPCE mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
... when we're in CPCE mode.