In the following program: ``` template<auto> struct A{}; template<class = A<[]{}>> struct B { using X = B<>; }; B<int> x; ``` compiled with `-std=c++20 -Wall -Wextra -pedantic-errors` flags, GCC prints false warning: ``` warning: no return statement in function returning non-void [-Wreturn-type] 4 | template<class = A<[]{}>> | ^~~~ ``` Demo: https://gcc.godbolt.org/z/bjrs5vMhj But actually `[]{}` is a lambda returning void, so no return statement is necessary.
Breakpoint 5, warning_at (richloc=0x7fffffffc490, opt=718, gmsgid=0x32d6798 "no return statement in function returning non-void") at /home/apinski/src/upstream-gcc/gcc/gcc/diagnostic.c:1654 1654 { (gdb) bt #0 warning_at (richloc=0x7fffffffc490, opt=718, gmsgid=0x32d6798 "no return statement in function returning non-void") at /home/apinski/src/upstream-gcc/gcc/gcc/diagnostic.c:1654 #1 0x0000000000c58304 in finish_function (inline_p=true) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/decl.c:17749 #2 0x0000000000cc3676 in finish_lambda_function (body=<statement_list 0x7ffff73b30a0>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/lambda.c:1576 #3 0x0000000000e6568c in tsubst_lambda_expr (t=<lambda_expr 0x7ffff73a9a40>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<function_decl 0x7ffff7397800 operator()>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:19670 #4 0x0000000000e6cf14 in tsubst_copy_and_build (t=<lambda_expr 0x7ffff73a9a40>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>, function_p=false, integral_constant_expression_p=true) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:21167 #5 0x0000000000e63d30 in tsubst_expr (t=<lambda_expr 0x7ffff73a9a40>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>, integral_constant_expression_p=true) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:19324 #6 0x0000000000e3a9a6 in tsubst_template_arg (t=<lambda_expr 0x7ffff73a9a40>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:12329 #7 0x0000000000e3eee4 in tsubst_template_args (t=<tree_vec 0x7ffff7389de0>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:13423 #8 0x0000000000e3fc6c in tsubst_aggr_type (t=<record_type 0x7ffff73b2930 A>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>, entering_scope=0) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:13627 #9 0x0000000000e4d0a5 in tsubst (t=<record_type 0x7ffff73b2930 A>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:15518 #10 0x0000000000e3a96a in tsubst_template_arg (t=<record_type 0x7ffff73b2930 A>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:12324 #11 0x0000000000e3eee4 in tsubst_template_args (t=<tree_vec 0x7ffff7389c80>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:13423 #12 0x0000000000e3fc6c in tsubst_aggr_type (t=<record_type 0x7ffff73b29d8 B>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>, entering_scope=0) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:13627 #13 0x0000000000e4d0a5 in tsubst (t=<record_type 0x7ffff73b29d8 B>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<type_decl 0x7ffff73b1428 X>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:15518 #14 0x0000000000e4a180 in tsubst_decl (t=<type_decl 0x7ffff73b1428 X>, args=<tree_vec 0x7ffff7389ee0>, complain=3) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:14815 #15 0x0000000000e4c863 in tsubst (t=<type_decl 0x7ffff73b1428 X>, args=<tree_vec 0x7ffff7389ee0>, complain=3, in_decl=<tree 0x0>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:15437 #16 0x0000000000e39e49 in instantiate_class_template_1 (type=<record_type 0x7ffff73b2b28 B>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:12076 #17 0x0000000000e3a8fc in instantiate_class_template (type=<record_type 0x7ffff73b2b28 B>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/pt.c:12311 #18 0x0000000000f1b0c8 in complete_type (type=<record_type 0x7ffff73b2b28 B>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/typeck.c:143 #19 0x0000000000c22f4b in start_decl_1 (decl=<var_decl 0x7ffff7ff6cf0 x>, initialized=false) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/decl.c:5765 #20 0x0000000000c22d75 in start_decl (declarator=0x4734190, declspecs=0x7fffffffd9d0, initialized=0, attributes=<tree 0x0>, prefix_attributes=<tree 0x0>, pushed_scope_p=0x7fffffffd880) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/decl.c:5731 #21 0x0000000000dae3d8 in cp_parser_init_declarator (parser=0x7ffff7272850, flags=0, decl_specifiers=0x7fffffffd9d0, checks=0x0, function_definition_allowed_p=true, member_p=false, declares_class_or_enum=0, function_definition_p=0x7fffffffd959, maybe_range_for_decl=0x0, init_loc=0x7fffffffd960, auto_result=0x7fffffffd968) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:22618 #22 0x0000000000d9f620 in cp_parser_simple_declaration (parser=0x7ffff7272850, function_definition_allowed_p=true, maybe_range_for_decl=0x0) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:15233 #23 0x0000000000d9f119 in cp_parser_block_declaration (parser=0x7ffff7272850, statement_p=false) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:15053 #24 0x0000000000d9ed67 in cp_parser_declaration (parser=0x7ffff7272850, prefix_attrs=<tree 0x0>) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:14919 #25 0x0000000000d9ee33 in cp_parser_toplevel_declaration (parser=0x7ffff7272850) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:14940 #26 0x0000000000d87d46 in cp_parser_translation_unit (parser=0x7ffff7272850) at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:4988 #27 0x0000000000df9101 in c_parse_file () at /home/apinski/src/upstream-gcc/gcc/gcc/cp/parser.c:47947 #28 0x0000000000fde522 in c_common_parse_file () at /home/apinski/src/upstream-gcc/gcc/gcc/c-family/c-opts.c:1238 #29 0x00000000017f2e8a in compile_file () at /home/apinski/src/upstream-gcc/gcc/gcc/toplev.c:452 #30 0x00000000017f5fdc in do_compile (no_backend=false) at /home/apinski/src/upstream-gcc/gcc/gcc/toplev.c:2158 #31 0x00000000017f63d6 in toplev::main (this=0x7fffffffdd82, argc=8, argv=0x7fffffffde88) at /home/apinski/src/upstream-gcc/gcc/gcc/toplev.c:2310 #32 0x0000000002f612b1 in main (argc=8, argv=0x7fffffffde88) at /home/apinski/src/upstream-gcc/gcc/gcc/main.c:39
(gdb) p debug_tree(0x7ffff73b22a0) <method_type 0x7ffff73b22a0 type <integer_type 0x7ffff72625e8 int public type_6 SI size <integer_cst 0x7ffff7264198 constant 32> unit-size <integer_cst 0x7ffff72641b0 constant 4> align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff72625e8 precision:32 min <integer_cst 0x7ffff7264150 -2147483648> max <integer_cst 0x7ffff7264168 2147483647> pointer_to_this <pointer_type 0x7ffff726aa80>> QI size <integer_cst 0x7ffff7264048 type <integer_type 0x7ffff72620a8 bitsizetype> constant 8> unit-size <integer_cst 0x7ffff7264060 type <integer_type 0x7ffff7262000 sizetype> constant 1> align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff73b22a0 method basetype <record_type 0x7ffff73b2c78 ._anon_2> arg-types <tree_list 0x7ffff73ac690 value <pointer_type 0x7ffff73b2dc8 type <record_type 0x7ffff73b21f8 ._anon_2> unsigned DI size <integer_cst 0x7ffff7242f48 constant 64> unit-size <integer_cst 0x7ffff7242f60 constant 8> align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type 0x7ffff73b2dc8> chain <tree_list 0x7ffff7258b68 value <void_type 0x7ffff7262f18 void>>>>
With just: template<auto = []{}> struct B { using X = B<>; }; B<> x; We get an ICE :).
Dup of bug 99902. *** This bug has been marked as a duplicate of bug 99902 ***