public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102514] New: The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator
@ 2021-09-28  9:07 xmh970252187 at gmail dot com
  2021-10-24  7:32 ` [Bug c++/102514] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: xmh970252187 at gmail dot com @ 2021-09-28  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102514
           Summary: The allocation function shall not be called when
                    existing an erroneous expression in
                    noptr-new-declarator
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xmh970252187 at gmail dot com
  Target Milestone: ---

````
struct C{
    void* operator new[](std::size_t N) noexcept(false){  // #1
        std::cout<<"abc\n";
        auto p =  malloc(10);
        return p;
    }
};
int n = -1;
auto ptr = new C[n];
std::cout<< ptr;
delete [] ptr;
````

GCC prints that `#1` is called and the address is non-null. According to
[expr.new] p9, the function at `#1` shall not be called, and since the function
has potential throwing specification, the new-expression should terminate by
throwing an exception.  

Example 2: 
````cpp
struct C2{
    void* operator new[](std::size_t N) noexcept{  // #2
        std::cout<<"abc\n";
        auto p =  malloc(10);
        return p;
    }
};
int n = -1;
auto ptr = new C2[n];
std::cout<< ptr;
delete [] ptr;
````
GCC calls `#2`, and the address is non-null.

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

end of thread, other threads:[~2023-03-20 10:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28  9:07 [Bug c++/102514] New: The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator xmh970252187 at gmail dot com
2021-10-24  7:32 ` [Bug c++/102514] " pinskia at gcc dot gnu.org
2021-10-25  1:10 ` xmh970252187 at gmail dot com
2023-03-20 10:08 ` 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).