https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128984
Bug ID: 128984
Summary: [C++26] compiler rejects a constexpr call to a
function returning a non-literal type that throws
before returning
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent.liu at arista dot com
Target Milestone: ---
With -std=c++26, GCC rejects a constant expression where a constexpr function
with a non-literal return type throws an exception before initializing its
return object.
My understanding is that this should be valid since initialisation of the
NotConstexpr never happens before the throw.
Originally found on gcc 16.2 but repros on godbolt with gcc trunk.
---
struct NotConstexpr {
~NotConstexpr() {}
};
constexpr auto foo() {
if consteval {
throw 0;
} else {
return NotConstexpr{};
}
}
consteval {
try {
foo();
} catch (int) {
}
}
---