https://bugs.llvm.org/show_bug.cgi?id=47047

Richard Smith <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Richard Smith <[email protected]> ---
Your testcase has undefined behavior; GCC is wrong to accept it.
std::allocator<int>::allocate only allocates memory for the array of ints, it
does not start the lifetime of any int objects. You need to create an int
object using std::construct_at before you can assign to it:

  std::allocator<int> alloc;
  int *p = alloc.allocate(1);
  std::construct_at(p);
  *p = 42;
  int i = *p;
  alloc.deallocate(p,1);

Then GCC and Clang both accept: https://godbolt.org/z/8j9Kas

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to