[llvm-bugs] [Bug 47047] Unexpected constexpr assignment error relating to object lifetime and std::allocator
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Aug 7 17:35:16 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47047
Richard Smith <richard-llvm at metafoo.co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200808/1daab4f7/attachment.html>
More information about the llvm-bugs
mailing list