https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122671
Bug ID: 122671
Summary: GCC fails to compile-time valid C++26 code using both
constexpr placement new (P2747R2) and constexpr
exceptions (P3068R6).
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mte.zych at gmail dot com
Target Milestone: ---
Hello!
GCC-16 does not compile the following C++26 code, which AFAIK is valid:
#include <new>
#include <memory>
consteval auto func ()
{
struct error { };
struct object
{
constexpr explicit object (int value)
{
if (value < 0) { throw error { }; }
}
};
try
{
struct storage
{
object* ptr;
constexpr storage ()
: ptr { std::allocator<object> { }.allocate(1) } { }
constexpr ~storage ()
{ std::allocator<object> { }.deallocate(ptr, 1); }
};
auto object_storage = storage { };
::new(object_storage.ptr) object { -1 };
}
catch (error&) { }
return true;
}
static_assert(func());
Compiler Explorer link: https://godbolt.org/z/K5K86qWvM
To me this looks like a bug in GCC, which is occurring when
an object is being created at compile-time via placement new,
inside a try & catch block, and its constructor throws an exception.
Thank you, Mateusz Zych