Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/ByteCode/cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}