[libcxx-commits] [libcxx] [libc++] Fix behavior for `get_temporary_buffer` with non-positive size (PR #206871)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 1 01:04:04 PDT 2026
================
@@ -38,5 +40,23 @@ int main(int, char**)
assert(reinterpret_cast<std::uintptr_t>(ip.first) % alignof(A) == 0);
std::return_temporary_buffer(ip.first);
+ // C++17 [depr.temporary.buffer]/4
+ // Returns: If n <= 0 or if no storage could be obtained,
+ // returns a pair P such that P.first is a null pointer value and P.second == 0;
+ {
+ std::pair<A*, std::ptrdiff_t> ret = std::get_temporary_buffer<A>(0);
+ assert(ret.first == NULL);
+ assert(ret.second == 0);
+ }
+ {
+ TEST_DIAGNOSTIC_PUSH
+ // This warning is coupled with completeness of control flow analysis which is affected by optimizations.
+ TEST_GCC_DIAGNOSTIC_IGNORED("-Wno-alloc-size-larger-than")
----------------
frederick-vs-ja wrote:
Simple `-Walloc-size-larger-than` (without `=`) doesn't work. `-Walloc-size-larger-than=` (with no argument) and `-Walloc-size-larger-than=42` (where `42` can be replaced with any valid number) work. All working forms seem a bit weird...
https://github.com/llvm/llvm-project/pull/206871
More information about the libcxx-commits
mailing list