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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Makes me wonder why finish_fname returns the IDENTIFIER_NODE rather than the
VAR_DECL when processing_template_decl, though if I comment that out it ICEs.
When DECL_INITIAL is __FUNCTION__ etc. IDENTIFIER_NODE, it is looked up using
lookup_name, which works fine if it is the template function in which
__FUNCTION__ has been referenced (ok e.g. when processing DECL_EXPR of
fun_name).  But for some reason
we don't find that VAR_DECL as local specialization and trigger
                  /* This can happen for a variable used in a
                     late-specified return type of a local lambda, or for a
                     local static or constant.  Building a new VAR_DECL
                     should be OK in all those cases.  */
                  r = tsubst_decl (t, args, complain);
                  if (local_specializations)
                    /* Avoid infinite recursion (79640).  */
                    register_local_specialization (r, t);
                  if (decl_maybe_constant_var_p (r))
                    {
                      /* We can't call cp_finish_decl, so handle the
                         initializer by hand.  */
                      tree init = tsubst_init (DECL_INITIAL (t), r, args,
                                               complain, in_decl);
which then doesn't work, either it finds a different __FUNCTION__ than it
should, e.g. for:
bool v;

template<class F>
void my_fun()
{
    auto fun = [&](auto res) {
        static constexpr char const* fun_name = __FUNCTION__;
        struct
        {
            constexpr const char* operator()() const { return v ? __FUNCTION__
: fun_name; };
        } t;
        t();
    };
    fun(12);
}
or it doesn't find it at all.

Reply via email to