https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123752
--- Comment #1 from John Drouhard <john at drouhard dot dev> ---
Not sure if this is a separate bug, but it I expand the test program a bit (so
the exception is still thrown from the consteval block), I can make gcc ICE at
cp/pt.cc:16738:
------
#include <meta>
#include <type_traits>
template <typename... T>
struct Test {
struct Storage;
consteval {
define_aggregate(^^Storage, {data_member_spec(^^T, {})...});
}
Storage storage_;
static constexpr auto fields =
define_static_array(nonstatic_data_members_of(^^Storage,
std::meta::access_context::current()));
};
template <size_t I, typename T>
constexpr auto &get(T &t) noexcept {
constexpr auto fields = std::remove_cvref_t<T>::fields;
static_assert(I < fields.size());
return t.storage_.[:fields[I]:];
}
int main() {
Test<int, double, std::string> val;
auto &s = get<2>(val);
}
------
test.cpp: In instantiation of 'struct Test<int, double,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
>':
required from here
test.cpp:23:34:
23 | Test<int, double, std::string> val;
| ^~~
test.cpp:7:3: error: uncaught exception of type 'std::meta::exception';
'what()': 'neither name nor bit_width specified'
7 | consteval {
| ^~~~~~~~~
test.cpp:10:11: error: 'Test<T>::storage_' has incomplete type
10 | Storage storage_;
| ^~~~~~~~
test.cpp:6:10: note: declaration of 'struct Test<int, double,
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >
>::Storage'
6 | struct Storage;
| ^~~~~~~
test.cpp: In instantiation of 'constexpr const std::span<std::meta::info,
18446744073709551615> Test<int, double, std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > >::fields':
required from 'constexpr auto& get(T&) [with long unsigned int I = 2; T =
Test<int, double, std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> > >]'
test.cpp:17:51:
17 | constexpr auto fields = std::remove_cvref_t<T>::fields;
| ^~~~~~
required from here
test.cpp:24:19:
24 | auto &s = get<2>(val);
| ~~~~~~^~~~~
test.cpp:12:25: error: uncaught exception of type 'std::meta::exception';
'what()': 'not a complete class type'
12 | static constexpr auto fields =
define_static_array(nonstatic_data_members_of(^^Storage,
std::meta::access_context::current()));
| ^~~~~~
test.cpp: In instantiation of 'constexpr auto& get(T&) [with long unsigned int
I = 2; T = Test<int, double, std::__cxx11::basic_string<char,
std::char_traits<char>, std::allocator<char> > >]':
required from here
test.cpp:24:19:
24 | auto &s = get<2>(val);
| ~~~~~~^~~~~
test.cpp:18:19: error: non-constant condition for static assertion
18 | static_assert(I < fields.size());
| ~~^~~~~~~~~~~~~~~
In file included from
/home/modules/rhel8/gcc-16-20260121/include/c++/16.0.1/bits/version.h:51,
from
/home/modules/rhel8/gcc-16-20260121/include/c++/16.0.1/meta:37,
from test.cpp:1:
in 'constexpr' expansion of 'fields.std::span<std::meta::info,
18446744073709551615>::operator[](2)'
test.cpp:19:29:
19 | return t.storage_.[:fields[I]:];
| ~~~~~~^
/home/modules/rhel8/gcc-16-20260121/include/c++/16.0.1/span:302:9: error:
'__builtin_expect((__idx >= ((const std::span<std::meta::info,
18446744073709551615>*)this)->std::span<std::meta::info,
18446744073709551615>::size()), 0)' is not a constant expression
302 | __glibcxx_assert(__idx < size());
| ^~~~~~~~~~~~~~~~
test.cpp:19:23: internal compiler error: in tsubst_splice_expr, at
cp/pt.cc:16738
19 | return t.storage_.[:fields[I]:];
| ~~^~~~~~~~~~~
/home/modules/rhel8/gcc-16-20260121/bin/../libexec/gcc/x86_64-pc-linux-gnu/16.0.1/cc1plus
-quiet -iprefix
/home/modules/rhel8/gcc-16-20260121/bin/../lib/gcc/x86_64-pc-linux-gnu/16.0.1/
-D_GNU_SOURCE test.cpp -quiet -dumpdir build-gcc/ -dumpbase test.cpp
-dumpbase-ext .cpp -mtune=generic -march=x86-64 -std=c++26 -freflection -o
/tmp/ccQlowjs.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
See <https://gcc.gnu.org/bugs/> for instructions.