https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120775
--- Comment #20 from Desmond Gold <cooky.ykooc922 at gmail dot com> ---
I discovered another bug which involves initializing reflection type with null
reflection within template body or during template instantiation:
using info = decltype(^^int);
inline constexpr info Ag {}; // ok
consteval info return_null() {
return info{};
}
template <typename>
struct S {
static constexpr info Bt {^^::}; // ok
static constexpr info Ct {}; // error during template definition
static constexpr info Dt = return_null(); // error upon instantiation
};
template struct S<int>; // this triggers error on S<int>::Dt
int main() {
template for (auto _ : {0}) {
constexpr info A {}; // error upon immediate expansion
}
}
Although it didn't ICE, it results in an error:
<source>:12:31: error: insufficient contextual information to determine type
[-Wtemplate-body]
12 | static constexpr info Ct {}; // error during template definition
| ^
<source>: In instantiation of 'constexpr const info S<int>::Dt':
required from here
<source>:16:17:
16 | template struct S<int>;
| ^~~~~~
<source>:13:43: error: insufficient contextual information to determine type
13 | static constexpr info Dt = return_null(); // error upon
instantiation
| ~~~~~~~~~~~^~
<source>: In function 'int main()':
<source>:20:27: error: insufficient contextual information to determine type
20 | constexpr info A {}; // error upon immediate expansion
| ^
https://godbolt.org/z/cfc3f47M6
There is no error in Clang Reflection Branch when compiling this code.