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
* [Bug c++/102514] The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator
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 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-24 7:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102514
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, clang, GCC, ICC and MSVC all have the same behavior for the testcase.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/102514] The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator
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
2 siblings, 0 replies; 4+ messages in thread
From: xmh970252187 at gmail dot com @ 2021-10-25 1:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102514
--- Comment #2 from jim x <xmh970252187 at gmail dot com> ---
It seems that they all do not obey [expr.new] p9, which says that
If the expression in a noptr-new-declarator is present, it is implicitly
converted to std::size_t. The expression is erroneous if:
- the expression is of non-class type and its value before converting to
std::size_t is less than zero;
- [...]
If the expression is erroneous after converting to std::size_t:
- if the expression is a core constant expression, the program is ill-formed;
- otherwise, an allocation function is not called; instead
- if the allocation function that would have been called has a non-throwing
exception specification ([except.spec]), the value of the new-expression is
the null pointer value of the required result type;
- otherwise, the new-expression terminates by throwing an exception of a type
that would match a handler ([except.handle]) of type
std::bad_array_new_
length.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/102514] The allocation function shall not be called when existing an erroneous expression in noptr-new-declarator
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
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2023-03-20 10:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102514
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=99934
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is Bug 99934
*** This bug has been marked as a duplicate of bug 99934 ***
^ 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).