From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C6738385843A; Fri, 3 Feb 2023 18:09:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6738385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675447796; bh=RREiIq8SknYxsbkN9/TucgmPTHLJwIrqUA7mgXXkT4I=; h=From:To:Subject:Date:In-Reply-To:References:From; b=D/yavzd39GITvDORHf8YgUkQyE0xKVE0Mp1aELkHoJSyFYDW4Vleh73P/LLUPRjYp +LVowrSUEGbbCAc0ry187t5npjl1cpUhgJgZA38mBcSSb1C3UvMsBF2Z9IevZok04b VanNlXzYRnJouer9chRkNtOmhvQIOtw+hXlRLEvA= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/108242] [10/11/12/13 Regression] '__FUNCTION__' was not declared when used inside a generic (templated) lambda declared inside a template function Date: Fri, 03 Feb 2023 18:09:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: c++-lambda, rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108242 --- Comment #5 from Jakub Jelinek --- 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 ICE= s. When DECL_INITIAL is __FUNCTION__ etc. IDENTIFIER_NODE, it is looked up usi= ng 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 =3D 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 =3D 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 void my_fun() { auto fun =3D [&](auto res) { static constexpr char const* fun_name =3D __FUNCTION__; struct { constexpr const char* operator()() const { return v ? __FUNCTIO= N__ : fun_name; }; } t; t(); }; fun(12); } or it doesn't find it at all.=