[Bug c++/86347] Incorrect call order of allocation function in new expression
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jun 28 15:40:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86347
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|WAITING |NEW
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to stinkingmadgod from comment #2)
> Apologies, not familiar with netiquette here
That's why you're asked to read https://gcc.gnu.org/bugs/ before creating a bug
report.
Reduced:
typedef decltype(sizeof(0)) size_t;
extern "C" int puts(const char*);
extern "C" void* malloc(size_t);
void* operator new(size_t n)
{
puts("new");
return malloc(n);
}
struct Y
{
Y() { puts("Y()"); }
Y(const Y&)
{
puts("Y(const Y&)");
throw "tantrum";
}
};
struct X {
X(Y) noexcept { }
};
int main()
{
try
{
Y y;
new X{y};
}
catch(...)
{
}
}
(In reply to stinkingmadgod from comment #0)
> Should have output
> new
> Y()
> Y(const Y&)
No, it should be:
Y()
new
Y(const Y&)
> But has output
> Y()
> Y(const Y&)
>
> Without the throw statement, it has output
> Y()
> Y(const Y&)
> new
Confirmed.
More information about the Gcc-bugs
mailing list