https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126112

            Bug ID: 126112
           Summary: [reflection] ICE when current_function() default
                    template argument is used inside a template function
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chzn at mail dot ustc.edu.cn
  Target Milestone: ---

https://godbolt.org/z/czcjTG9Pq

the following code:

```
#include <iostream>
#include <meta>

template<std::meta::info i=std::meta::current_function()>
consteval std::string_view current_function_name() {
    return std::meta::display_string_of(i);
}

template<typename T>
void f() {
    std::cout<<current_function_name()<<std::endl;
}

int main() {
    f<int>();
}
```

result in

```
<source>: In instantiation of 'consteval std::string_view
current_function_name() [with std::meta::info i = int; std::string_view =
std::basic_string_view<char>]':
<source>:11:37:   required from 'void f() [with T = int]'
   11 |     std::cout<<current_function_name()<<std::endl;
      |                ~~~~~~~~~~~~~~~~~~~~~^~
<source>:15:11:   required from here
   15 |     f<int>();
      |     ~~~~~~^~
<source>:6:40: internal compiler error: Segmentation fault
    6 |     return std::meta::display_string_of(i);
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
0x2b1e068 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x2b12cab internal_error(char const*, ...)
        ???:0
0xb54868 resolve_args(vec<tree_node*, va_gc, vl_embed>*, int)
        ???:0
0xb723c1 build_new_function_call(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0xe2f4c5 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xdf1acd instantiate_decl(tree_node*, bool, bool)
        ???:0
0x1933b33 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x1933d75 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x1937757 walk_tree_without_duplicates_1(tree_node**, tree_node*
(*)(tree_node**, int*, void*), void*, tree_node* (*)(tree_node**, int*,
tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, false,
default_hash_traits<tree_node*> >*))
        ???:0
0xbb9133 cxx_constant_value(tree_node*, tree_node*, int)
        ???:0
0x1933b33 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x1933fcd walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0x1933d75 walk_tree_1(tree_node**, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*,
tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*),
void*, hash_set<tree_node*, false, default_hash_traits<tree_node*> >*))
        ???:0
0xbe9edc cp_fold_function(tree_node*)
        ???:0
0xc40987 finish_function(bool)
        ???:0
0xdf1acd instantiate_decl(tree_node*, bool, bool)
        ???:0
0xdfb8ea instantiate_pending_templates(int)
        ???:0
0xc5f078 c_parse_final_cleanups()
        ???:0
0xf1d978 c_common_parse_file()
        ???:0
/cefs/95/9536ed1ff029239b9f4ddada_gcc-trunk-20260704/bin/../libexec/gcc/x86_64-linux-gnu/17.0.0/cc1plus
-quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/95/9536ed1ff029239b9f4ddada_gcc-trunk-20260704/bin/../lib/gcc/x86_64-linux-gnu/17.0.0/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/output.s- -dumpbase example.cpp
-dumpbase-ext .cpp -mtune=generic -march=x86-64 -g -std=c++26
-fdiagnostics-color=always -fno-verbose-asm -freflection -o /tmp/ccuptAAA.s
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.
```

Reply via email to