[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 01:08:18 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:

That's a bit unfortunate. I think I'd go for the `=` version without any number. (Also, maybe a GCC bug report?)

https://github.com/llvm/llvm-project/pull/206871


More information about the libcxx-commits mailing list