public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111854] New: new align_val_t usual deallocation
@ 2023-10-17 22:06 barry.revzin at gmail dot com
  2023-10-17 22:08 ` [Bug c++/111854] new (align_val_t) should be ill-formed pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: barry.revzin at gmail dot com @ 2023-10-17 22:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

            Bug ID: 111854
           Summary: new align_val_t usual deallocation
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

gcc accepts this program (copied from the MSVC documentation for
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2956?view=msvc-170)
without any warning or error:

#include <new>
struct T {};

int main()
{
    T* p = new (std::align_val_t{64}) T; // C2956
    delete p; // ordinary, not over-aligned delete
}

But this should be ill-formed, violating:
https://eel.is/c++draft/expr.new#28.sentence-3

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
@ 2023-10-17 22:08 ` pinskia at gcc dot gnu.org
  2023-10-17 22:10 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-17 22:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I don't see any issues with this program at compile time (runtime it would be
undefined though).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
  2023-10-17 22:08 ` [Bug c++/111854] new (align_val_t) should be ill-formed pinskia at gcc dot gnu.org
@ 2023-10-17 22:10 ` pinskia at gcc dot gnu.org
  2023-10-17 22:11 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-17 22:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The reason why is you are using the global operator new here rather than trying
the one inside T.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
  2023-10-17 22:08 ` [Bug c++/111854] new (align_val_t) should be ill-formed pinskia at gcc dot gnu.org
  2023-10-17 22:10 ` pinskia at gcc dot gnu.org
@ 2023-10-17 22:11 ` pinskia at gcc dot gnu.org
  2023-10-17 22:14 ` barry.revzin at gmail dot com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-17 22:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
as explained.

GCC correctly rejects:
```
#include <new>
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
```

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
                   ` (2 preceding siblings ...)
  2023-10-17 22:11 ` pinskia at gcc dot gnu.org
@ 2023-10-17 22:14 ` barry.revzin at gmail dot com
  2023-10-17 22:19 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: barry.revzin at gmail dot com @ 2023-10-17 22:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

--- Comment #4 from Barry Revzin <barry.revzin at gmail dot com> ---
The standard says this should be ill-formed.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
                   ` (3 preceding siblings ...)
  2023-10-17 22:14 ` barry.revzin at gmail dot com
@ 2023-10-17 22:19 ` pinskia at gcc dot gnu.org
  2023-10-17 22:22 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-17 22:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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 ...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
                   ` (4 preceding siblings ...)
  2023-10-17 22:19 ` pinskia at gcc dot gnu.org
@ 2023-10-17 22:22 ` pinskia at gcc dot gnu.org
  2023-10-18  2:21 ` rs2740 at gmail dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-17 22:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
                   ` (5 preceding siblings ...)
  2023-10-17 22:22 ` pinskia at gcc dot gnu.org
@ 2023-10-18  2:21 ` rs2740 at gmail dot com
  2023-10-18  9:32 ` redi at gcc dot gnu.org
  2023-10-18  9:44 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rs2740 at gmail dot com @ 2023-10-18  2:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

TC <rs2740 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rs2740 at gmail dot com

--- Comment #7 from TC <rs2740 at gmail dot com> ---
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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
                   ` (6 preceding siblings ...)
  2023-10-18  2:21 ` rs2740 at gmail dot com
@ 2023-10-18  9:32 ` redi at gcc dot gnu.org
  2023-10-18  9:44 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-10-18  9:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

Jonathan Wakely <redi at gcc dot gnu.org> 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 <redi at gcc dot gnu.org> ---
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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/111854] new (align_val_t) should be ill-formed
  2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
                   ` (7 preceding siblings ...)
  2023-10-18  9:32 ` redi at gcc dot gnu.org
@ 2023-10-18  9:44 ` redi at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: redi at gcc dot gnu.org @ 2023-10-18  9:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111854

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-10-18  9:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-17 22:06 [Bug c++/111854] New: new align_val_t usual deallocation barry.revzin at gmail dot com
2023-10-17 22:08 ` [Bug c++/111854] new (align_val_t) should be ill-formed pinskia at gcc dot gnu.org
2023-10-17 22:10 ` pinskia at gcc dot gnu.org
2023-10-17 22:11 ` pinskia at gcc dot gnu.org
2023-10-17 22:14 ` barry.revzin at gmail dot com
2023-10-17 22:19 ` pinskia at gcc dot gnu.org
2023-10-17 22:22 ` pinskia at gcc dot gnu.org
2023-10-18  2:21 ` rs2740 at gmail dot com
2023-10-18  9:32 ` redi at gcc dot gnu.org
2023-10-18  9:44 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).