From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 000FA3945C19; Wed, 18 Mar 2020 12:17:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 000FA3945C19 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584533831; bh=ItAUl+rax2GL4OaR0qZnqUzBs28mfgILsFBzqckBuM0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=s31RAxYL6Qa0hDSk5TW9o7/fIYXJLYWa4Onq0Mki6QfiY6HpeaO6fnuclO9iQBSt3 dlnMadgs/l8ARp8Ga6uALHbX7xIsWdeM283ZsUqMPHJAcKeVUId2A4GsKP4wkixOJi wwTHfkFa/ye8f1Enk6TJxrTydtGcaZmmPhwMclVg= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/94147] mangling of lambdas in initializers is wrong Date: Wed, 18 Mar 2020 12:17:10 +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: 10.0 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: nathan at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2020 12:17:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94147 --- Comment #1 from CVS Commits --- The master branch has been updated by Nathan Sidwell : https://gcc.gnu.org/g:11cf25c40e3f586d19474108c78a2dfad7925902 commit r10-7243-g11cf25c40e3f586d19474108c78a2dfad7925902 Author: Nathan Sidwell Date: Wed Mar 18 05:16:28 2020 -0700 PR c++/94147 - mangling of lambdas assigned to globals This patch implements Jason's suggestion of pushing a lambda scope when parsing a global variable initializer. That bit worked fine, but happened to cause g++.dg/opt/dump1.C to not give any used-but-not-defined warnings. The reason was no_linkage_check, which considers any lambda that has an extra-scope to have linkage. Which is technically correct. Except that we think that all types that have linkage have external linkage. Our representation of linkage and visibility is somewhat inaccurate, particularly when it comes to types. We have TREE_PUBLIC, DECL_EXTERNAL, DECL_VISIBILITY, DECL_COMDAT, DECL_NOT_REALLY_EXTERN. It could really do with a through cleanup, but that won't be a simple task. The best I could come up with was seeing if the extra scope was a VAR_DECL, and if that was TREE_PUBLIC and the var was inline (its COMDATness is sadly not set at that point) or a template instantiation, then the lambda had linkage. Otherwise it's as-if it has no-linkage from the POV of compiler internals. This is an ABI change (so we should document it), but it's changing mangling from an unpredictable (in practice) counter, to something the ABI defines. So I'm not concerned about mangling-changed warnings, or preserving the broken mangling under some ABI selection flag. Code that did this worked by accident within a single TU. It'll continue to work by design there, and across TUs. * parser.c (cp_parser_init_declarator): Namespace-scope variabl= es provide a lambda scope. * tree.c (no_linkage_check): Lambdas with a variable for extra scope have a linkage from the variable.=