Timm Baeder 9387fd9631
[clang][bytecode] Fix diagnosing replaceable global allocator functions (#126717)
Don't return true here in InvalidNewDeleteExpr just because we are in
C++26 mode. This invalid there as well.

Testcase reduced from
libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique_for_overwrite.pass.cpp
2025-02-11 16:51:21 +01:00

34 lines
922 B
C++

// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=ref,both %s
// RUN: %clang_cc1 -std=c++26 -fsyntax-only -fcxx-exceptions -verify=expected,both %s -fexperimental-new-constant-interpreter
namespace std {
using size_t = decltype(sizeof(0));
}
namespace VoidCast {
constexpr void* p = nullptr;
constexpr int* q = static_cast<int*>(p);
static_assert(q == nullptr);
}
namespace ReplaceableAlloc {
struct F {
static void* operator new(std::size_t n) {
return nullptr; // both-warning {{should not return a null pointer}}
}
};
constexpr F *createF() {
return new F(); // both-note {{call to class-specific 'operator new'}}
}
constexpr bool foo() {
F *f = createF(); // both-note {{in call to}}
delete f;
return true;
}
static_assert(foo()); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
}