https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102626
Bug ID: 102626
Summary: [c++20] compiler crash when invoking constexpr
function in the constructor of template class
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: royalbee at gmail dot com
Target Milestone: ---
* version: g++ (Compiler-Explorer-Build-gcc--binutils-2.36.1) 11.2.0
* compile options: -std=c++20 -O3
* online example: https://godbolt.org/z/hz61so9vc
* compiling produces error:
during RTL pass: expand
<source>: In function 'int main()':
<source>:15:50: internal compiler error: Segmentation fault
15 | auto p = packed<A, &A::x, &A::y>{std::span(buf)};
| ^
0x1786229 internal_error(char const*, ...)
???:0
0xff757b make_decl_rtl(tree_node*)
???:0
0x8f9536 expand_call(tree_node*, rtx_def*, int)
???:0
0xa0ff2e expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
ASM generation compiler returned: 1
during RTL pass: expand
<source>: In function 'int main()':
<source>:15:50: internal compiler error: Segmentation fault
15 | auto p = packed<A, &A::x, &A::y>{std::span(buf)};
| ^
0x1786229 internal_error(char const*, ...)
???:0
0xff757b make_decl_rtl(tree_node*)
???:0
0x8f9536 expand_call(tree_node*, rtx_def*, int)
???:0
0xa0ff2e expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
???:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Execution build compiler returned: 1
* code:
#include <span>
template <typename T, auto ...ms> struct packed;
template <typename S, typename ...Ts, Ts S::* ...ms>
struct packed<S, ms...> {
static constexpr size_t size() { return (sizeof(S{}.*ms) + ...); }
std::span<std::byte> buf;
packed(auto b) : buf(b.first(size())) {} //<<< removing call to size() fixes
the issue
};
int main() {
struct A {int x, y;};
std::byte buf[100];
auto p = packed<A, &A::x, &A::y>{std::span(buf)};
static_assert(p.size() == 8);
return 0;
}