[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 --- Comment #9 from Jonathan Wakely --- (In reply to Andrew Pinski from comment #6) > You are mixing up 2 different things. > First this is about if the operator new is valid and it is because there is > a corresponding placement delete operator (this would be rejected at compile > time). The point is that [expr.new] p28 says it's ill-formed. Yes, there's a corresponding delete operator, but it's one of the "usual deallocation functions", and that isn't an allowed lookup result for a placement new expression. This might seem surprising, but it's what the standard says. > Second is if you can call the normal delete on an allocated memory from that > inplacement new call. The answer is yes you can and not invoke undefined > behavior. That's not what the standard says. 'delete p' will call either operator delete(void*) or operator delete(void*, size_t), and those functions have a precondition that the pointer was obtained from an allocation function without an alignment parameter. See [new.delete.single] p11.
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 Jonathan Wakely changed: What|Removed |Added Resolution|INVALID |--- Keywords||accepts-invalid Ever confirmed|0 |1 Status|RESOLVED|SUSPENDED Last reconfirmed||2023-10-18 --- Comment #8 from Jonathan Wakely --- I agree this is an accepts-invalid bug. But I also agree that it's a bit weird that the standard considers this a placement new expression even though it finds a standard-defined allocation function. Suspending pending a response to Tim's question to CWG four hours ago.
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 TC changed: What|Removed |Added CC||rs2740 at gmail dot com --- Comment #7 from TC --- Per https://eel.is/c++draft/basic.stc.dynamic.deallocation#3.sentence-4, `void operator delete(void*, std::size_t, std::align_val_t);` is a usual deallocation function just like `void operator delete(void*, std::size_t);` and therefore this should be rejected for the same reason that the example in comment #3 is rejected.
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 --- Comment #6 from Andrew Pinski --- You are mixing up 2 different things. First this is about if the operator new is valid and it is because there is a corresponding placement delete operator (this would be rejected at compile time). Second is if you can call the normal delete on an allocated memory from that inplacement new call. The answer is yes you can and not invoke undefined behavior.
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 --- Comment #5 from Andrew Pinski --- Why? as there is: void operator delete(void*, std::size_t, std::align_val_t) noexcept __attribute__((__externally_visible__)); void operator delete[](void*, std::size_t, std::align_val_t) noexcept __attribute__((__externally_visible__)); in the new header ...
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 --- Comment #4 from Barry Revzin --- The standard says this should be ill-formed.
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 Andrew Pinski changed: What|Removed |Added Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED --- Comment #3 from Andrew Pinski --- as explained. GCC correctly rejects: ``` #include struct T { void* operator new(std::size_t, std::size_t); // Placement allocation function void operator delete(void*, std::size_t); // now considered a usual deallocation function }; T* p = new (0) T; // error: usual deallocation function would be chosen as placement deallocation function ```
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 --- Comment #2 from Andrew Pinski --- The reason why is you are using the global operator new here rather than trying the one inside T.
[Bug c++/111854] new (align_val_t) should be ill-formed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854 --- Comment #1 from Andrew Pinski --- I don't see any issues with this program at compile time (runtime it would be undefined though).