Skip to content

Commit 3b8a18c

Browse files
authored
[clang][bytecode] Fix contains check using llvm::find (#149050)
We need to compare to the end() interator.
1 parent 73630d5 commit 3b8a18c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ bool CheckConst(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
574574

575575
// The This pointer is writable in constructors and destructors,
576576
// even if isConst() returns true.
577-
if (llvm::find(S.InitializingBlocks, Ptr.block()))
577+
if (llvm::is_contained(S.InitializingBlocks, Ptr.block()))
578578
return true;
579579

580580
const QualType Ty = Ptr.getType();

clang/test/AST/ByteCode/placement-new.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,11 @@ namespace bitcast {
486486
}
487487
static_assert(foo() == 0);
488488
}
489+
490+
constexpr int modify_const_variable() {
491+
const int a = 10;
492+
new ((int *)&a) int(12); // both-note {{modification of object of const-qualified type 'const int' is not allowed in a constant expression}}
493+
return a;
494+
}
495+
static_assert(modify_const_variable()); // both-error {{not an integral constant expression}} \
496+
// both-note {{in call to}}

clang/test/SemaCXX/cxx2c-constexpr-placement-new.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -std=c++2c -verify %s
2+
// RUN: %clang_cc1 -std=c++2c -verify %s -fexperimental-new-constant-interpreter
23

34

45
namespace std {

0 commit comments

Comments
 (0)