Skip to content

Commit ede75e5

Browse files
authored
[clang][bytecode] Don't diagnose const assignments... (#192593)
... when we're in CPCE mode.
1 parent fca80b4 commit ede75e5

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,11 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
579579
if (llvm::is_contained(S.InitializingBlocks, Ptr.block()))
580580
return true;
581581

582-
const QualType Ty = Ptr.getType();
583-
const SourceInfo &Loc = S.Current->getSource(OpPC);
584-
S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
582+
if (!S.checkingPotentialConstantExpression()) {
583+
const QualType Ty = Ptr.getType();
584+
const SourceInfo &Loc = S.Current->getSource(OpPC);
585+
S.FFDiag(Loc, diag::note_constexpr_modify_const_type) << Ty;
586+
}
585587
return false;
586588
}
587589

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,3 +1345,12 @@ namespace ExpandOnOPTEPointers {
13451345
}
13461346
static_assert(test());
13471347
}
1348+
1349+
namespace ConstIntPotentialConstantExpr {
1350+
/// NO error about a constexpr function that's never a constant expression.
1351+
constexpr int Const() {
1352+
const int a = 10; // both-note {{declared const here}}
1353+
a = 20; // both-error {{cannot assign to variable 'a' with const-qualified type 'const int'}}
1354+
return 1;
1355+
}
1356+
}

0 commit comments

Comments
 (0)