From 6b83a3c6e3b408a00a0fb326828571770706ec24 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 7 May 2018 19:50:16 -0400 Subject: [PATCH] PR c++/85646 - lambda visibility. * decl2.c (determine_visibility): Don't mess with template arguments from the containing scope. (vague_linkage_p): Check DECL_ABSTRACT_P before looking at a 'tor thunk. From-SVN: r260017 --- gcc/cp/ChangeLog | 8 +++++++ gcc/cp/decl2.c | 24 ++++++------------- gcc/testsuite/g++.dg/ext/visibility/lambda1.C | 14 +++++++++++ 3 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/visibility/lambda1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 75f52078faa..65991150ef0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2018-05-07 Jason Merrill + + PR c++/85646 - lambda visibility. + * decl2.c (determine_visibility): Don't mess with template arguments + from the containing scope. + (vague_linkage_p): Check DECL_ABSTRACT_P before looking at a 'tor + thunk. + 2018-05-07 Nathan Sidwell Remove fno-for-scope diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index b0bf8241f71..9aae34a814c 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1939,10 +1939,13 @@ vague_linkage_p (tree decl) { if (!TREE_PUBLIC (decl)) { - /* maybe_thunk_body clears TREE_PUBLIC on the maybe-in-charge 'tor - variants, check one of the "clones" for the real linkage. */ + /* maybe_thunk_body clears TREE_PUBLIC and DECL_ABSTRACT_P on the + maybe-in-charge 'tor variants; in that case we need to check one of + the "clones" for the real linkage. But only in that case; before + maybe_clone_body we haven't yet copied the linkage to the clones. */ if ((DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl) || DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl)) + && !DECL_ABSTRACT_P (decl) && DECL_CHAIN (decl) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl))) return vague_linkage_p (DECL_CHAIN (decl)); @@ -2422,21 +2425,8 @@ determine_visibility (tree decl) } /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set, - but have no TEMPLATE_INFO. Their containing template - function does, and the local class could be constrained - by that. */ - if (DECL_LANG_SPECIFIC (fn) && DECL_USE_TEMPLATE (fn)) - template_decl = fn; - else if (template_decl) - { - /* FN must be a regenerated lambda function, since they don't - have template arguments. Find a containing non-lambda - template instantiation. */ - tree ctx = fn; - while (ctx && !get_template_info (ctx)) - ctx = get_containing_scope (ctx); - template_decl = ctx; - } + but have no TEMPLATE_INFO, so don't try to check it. */ + template_decl = NULL_TREE; } else if (VAR_P (decl) && DECL_TINFO_P (decl) && flag_visibility_ms_compat) diff --git a/gcc/testsuite/g++.dg/ext/visibility/lambda1.C b/gcc/testsuite/g++.dg/ext/visibility/lambda1.C new file mode 100644 index 00000000000..359f8e4af5a --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/visibility/lambda1.C @@ -0,0 +1,14 @@ +// PR c++/85646 +// { dg-do compile { target c++11 } } +// { dg-additional-options -fvisibility=hidden } + +template +void foo() { + struct inner { + inner() { + (void)([this] { }); + } + }; +} + +int main() { foo(); } -- 2.30.2