https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122354
Bug ID: 122354
Summary: Segmentation fault with template function
Product: gcc
Version: 15.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: qingren2hxb at gmail dot com
Target Milestone: ---
Created attachment 62591
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62591&action=edit
bug report by using -freport-bug
========================================
$g++ -v
Using built-in specs.
COLLECT_GCC=/workspace/installation/bin/g++
COLLECT_LTO_WRAPPER=/workspace/installation/libexec/gcc/x86_64-pc-linux-gnu/15.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /workspace/gcc/configure --prefix=/workspace/installation
--enable-coverage --enable-checking --disable-multilib --disable-shared
--disable-bootstrap --enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.1.0 (GCC)
========================================
// test.C
template<typename T>
concept C1 = true;
template<typename U>
concept CustomConceptWithTypeVar {
using MyTypeAlias = int;
} requires(C1<U>);
template <typename X>
class NestedClass {
public:
template<CustomConceptWithTypeVar Y>
static constexpr bool inner_helper() { return true; }
static constexpr auto result = inner_helper<X>();
};
int main() {
NestedClass<int>::result;
return 0;
}
========================================
$ g++ -std=c++20 test.C
test.C:5:34: error: expected '=' before '{' token
5 | concept CustomConceptWithTypeVar {
| ^
test.C:7:2: error: expected ';' before 'requires'
7 | } requires(C1<U>);
| ^~~~~~~~~
| ;
test.C:12:14: error: 'CustomConceptWithTypeVar' has not been declared
[-Wtemplate-body]
12 | template<CustomConceptWithTypeVar Y>
| ^~~~~~~~~~~~~~~~~~~~~~~~
test.C: In instantiation of 'constexpr const auto NestedClass<int>::result':
test.C:15:27: required from 'class NestedClass<int>'
15 | static constexpr auto result = inner_helper<X>();
| ^~~~~~
test.C:19:21: required from here
19 | NestedClass<int>::result;
| ^~
test.C:15:51: internal compiler error: Segmentation fault
15 | static constexpr auto result = inner_helper<X>();
| ~~~~~~~~~~~~~~~^~
0x5d4e2e6 internal_error(char const*, ...)
/workspace/gcc/gcc/diagnostic-global-context.cc:517
0x270d8a0 crash_signal
/workspace/gcc/gcc/toplev.cc:322
0xec30f6 tree_check(tree_node*, char const*, int, char const*, tree_code)
/workspace/gcc/gcc/tree.h:3691
0x153aa2a tsubst_baselink
/workspace/gcc/gcc/cp/pt.cc:17458
0x155e22b tsubst_expr(tree_node*, tree_node*, int, tree_node*)
/workspace/gcc/gcc/cp/pt.cc:20941
0x15619f2 tsubst_expr(tree_node*, tree_node*, int, tree_node*)
/workspace/gcc/gcc/cp/pt.cc:21329
0x153c160 tsubst_init
/workspace/gcc/gcc/cp/pt.cc:17700
0x1590590 regenerate_decl_from_template
/workspace/gcc/gcc/cp/pt.cc:27360
0x1592d63 instantiate_body
/workspace/gcc/gcc/cp/pt.cc:27672
0x15966df instantiate_decl(tree_node*, bool, bool)
/workspace/gcc/gcc/cp/pt.cc:28026
0x10fcb6c cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int,
cp_decomp*)
/workspace/gcc/gcc/cp/decl.cc:8833
0x1169a73 finish_static_data_member_decl(tree_node*, tree_node*, bool,
tree_node*, int)
/workspace/gcc/gcc/cp/decl2.cc:1021
0x150dbd4 instantiate_class_template(tree_node*)
/workspace/gcc/gcc/cp/pt.cc:12804
0x16c0df7 complete_type(tree_node*)
/workspace/gcc/gcc/cp/typeck.cc:138
0x13aeded cp_parser_nested_name_specifier_opt
/workspace/gcc/gcc/cp/parser.cc:7528
0x13e8618 cp_parser_simple_type_specifier
/workspace/gcc/gcc/cp/parser.cc:21091
0x13e6d40 cp_parser_type_specifier
/workspace/gcc/gcc/cp/parser.cc:20743
0x13dae42 cp_parser_decl_specifier_seq
/workspace/gcc/gcc/cp/parser.cc:17251
0x13d73e0 cp_parser_simple_declaration
/workspace/gcc/gcc/cp/parser.cc:16401
0x13d731e cp_parser_block_declaration
/workspace/gcc/gcc/cp/parser.cc:16347
Please submit a full bug report, with preprocessed source.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions