https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120775
--- Comment #9 from Desmond Gold <cooky.ykooc922 at gmail dot com> ---
I tried to wrap the declarations using "if not consteval { ... }" which seems
to silence the ICE:
using info = decltype(^^::);
consteval info identity(info i) { return i; }
consteval int something_of(info) { return 10; }
consteval void do_something(info) {}
void fox() {
if not consteval {
constexpr info X {};
constexpr info A = ^^::;
constexpr info B = identity(A);
static constexpr info D = ^^::;
static_assert(X == info{});
static_assert(A == ^^::);
static_assert(B == ^^::);
static_assert(D == ^^::);
consteval {
do_something(X);
do_something(A);
int H = something_of(A);
constexpr int I = something_of(A);
}
}
}
However, the ICE resurfaces when referencing the constexpr variable of a
consteval-only type:
using info = decltype(^^::);
consteval info identity(info i) { return i; }
consteval int something_of(info) { return 10; }
consteval void do_something(info) {}
void fox() {
if not consteval {
constexpr info X {};
constexpr info A = ^^::;
constexpr info B = identity(A);
static constexpr info D = ^^::;
static_assert(X == info{});
static_assert(A == ^^::);
static_assert(B == ^^::);
static_assert(D == ^^::);
consteval {
do_something(X);
do_something(A);
int H = something_of(A);
constexpr int I = something_of(A);
}
// ICE
// do_something(X);
// do_something(A);
// do_something_runtime<X>();
// do_something_runtime<A>();
// int C = something_of(A);
// constexpr int E = something_of(A);
// identity(A);
// identity(B);
}
}
Uncommenting the line one at a time will produce an ICE output
https://godbolt.org/z/9xWhbYhbz