[libcxx-commits] [libcxx] [libc++] Fix behavior for `get_temporary_buffer` with non-positive size (PR #206871)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 1 00:55:06 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")
----------------
philnik777 wrote:
```suggestion
TEST_GCC_DIAGNOSTIC_IGNORED("-Walloc-size-larger-than")
```
I don't know whether the `no-` version also works, but this is definitely the convention in libc++.
https://github.com/llvm/llvm-project/pull/206871
More information about the libcxx-commits
mailing list