https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123664
Bug ID: 123664
Summary: ICE in fold_convert_loc, at fold-const.cc when
constexpr-initializing pointer-to-member-function in a
template instantiation
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jirehguo at tju dot edu.cn
Target Milestone: ---
Compiler Explorer: https://godbolt.org/z/91ThqMzMK
The following c++ code crash gcc trunk with -std=c++20 flag.
Goes back to 10.3 with checking.
While clang accepts it.
Code:
```cpp
struct Base {
virtual void doit(int) const;
};
struct Derived : Base {
void doit(int) const;
};
using fn_t = void (Base::*)(int) const;
struct help {
fn_t ptr;
};
template <typename T> auto generate(T) {
constexpr help h(static_cast<fn_t>(&Derived::doit));
}
template <class> struct A { A(); };
template <class V> A<V>::A() {
int values[]{};
for (int i : values)
generate(i);
}
```
Stack dump:
```
<source>: In instantiation of 'auto generate(T) [with T = int]':
required from here
<source>:18:13:
18 | generate(i);
| ~~~~~~~~^~~
<source>:12:18: internal compiler error: in fold_convert_loc, at
fold-const.cc:2794
12 | constexpr help h(static_cast<fn_t>(&Derived::doit));
| ^
0x2950a78 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
???:0
0x294583b internal_error(char const*, ...)
???:0
0xb1ec34 fancy_abort(char const*, int, char const*)
???:0
0xdc7c3d instantiate_decl(tree_node*, bool, bool)
???:0
0xc36823 maybe_instantiate_decl(tree_node*)
???:0
0xc387e7 mark_used(tree_node*, int)
???:0
0xb5765e build_new_function_call(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
???:0
0xe02f35 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0xd64c03 c_parse_file()
???:0
0xeeed49 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1
```