Commit bd65538a by Jason Merrill Committed by Jason Merrill

PR c++/47877 - -fvisibility-inlines-hidden and member templates.

DECL_VISIBILITY_SPECIFIED is also true if an enclosing scope has explicit
visibility, and we don't want that to override -fvisibility-inlines-hidden.
So check for the attribute specifically on the function, like we already do
for template argument visibility restriction.

	* decl2.c (determine_visibility): -fvisibility-inlines-hidden beats
	explicit class visibility for a template.

From-SVN: r279960
parent 66b01cc3
2020-01-07 Jason Merrill <jason@redhat.com>
PR c++/47877 - -fvisibility-inlines-hidden and member templates.
* decl2.c (determine_visibility): -fvisibility-inlines-hidden beats
explicit class visibility for a template.
2020-01-07 Richard Sandiford <richard.sandiford@arm.com> 2020-01-07 Richard Sandiford <richard.sandiford@arm.com>
* mangle.c (mangle_type_attribute_p): New function, split out from... * mangle.c (mangle_type_attribute_p): New function, split out from...
......
...@@ -2629,6 +2629,7 @@ determine_visibility (tree decl) ...@@ -2629,6 +2629,7 @@ determine_visibility (tree decl)
tree attribs = (TREE_CODE (decl) == TYPE_DECL tree attribs = (TREE_CODE (decl) == TYPE_DECL
? TYPE_ATTRIBUTES (TREE_TYPE (decl)) ? TYPE_ATTRIBUTES (TREE_TYPE (decl))
: DECL_ATTRIBUTES (decl)); : DECL_ATTRIBUTES (decl));
tree attr = lookup_attribute ("visibility", attribs);
if (args != error_mark_node) if (args != error_mark_node)
{ {
...@@ -2636,7 +2637,7 @@ determine_visibility (tree decl) ...@@ -2636,7 +2637,7 @@ determine_visibility (tree decl)
if (!DECL_VISIBILITY_SPECIFIED (decl)) if (!DECL_VISIBILITY_SPECIFIED (decl))
{ {
if (!DECL_VISIBILITY_SPECIFIED (pattern) if (!attr
&& determine_hidden_inline (decl)) && determine_hidden_inline (decl))
DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
else else
...@@ -2650,7 +2651,7 @@ determine_visibility (tree decl) ...@@ -2650,7 +2651,7 @@ determine_visibility (tree decl)
if (args if (args
/* Template argument visibility outweighs #pragma or namespace /* Template argument visibility outweighs #pragma or namespace
visibility, but not an explicit attribute. */ visibility, but not an explicit attribute. */
&& !lookup_attribute ("visibility", attribs)) && !attr)
{ {
int depth = TMPL_ARGS_DEPTH (args); int depth = TMPL_ARGS_DEPTH (args);
if (DECL_VISIBILITY_SPECIFIED (decl)) if (DECL_VISIBILITY_SPECIFIED (decl))
......
// PR c++/47877
// { dg-options "-fvisibility-inlines-hidden" }
// { dg-require-visibility "" }
// { dg-final { scan-hidden "_ZN3Foo3barIS_EEvv" } }
struct __attribute__((visibility("default"))) Foo {
template <class C> inline void bar() {};
};
int main()
{
Foo().bar<Foo>();
}
...@@ -2903,8 +2903,8 @@ extern void decl_value_expr_insert (tree, tree); ...@@ -2903,8 +2903,8 @@ extern void decl_value_expr_insert (tree, tree);
#define DECL_VISIBILITY(NODE) \ #define DECL_VISIBILITY(NODE) \
(DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.visibility) (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.visibility)
/* Nonzero means that the decl had its visibility specified rather than /* Nonzero means that the decl (or an enclosing scope) had its
being inferred. */ visibility specified rather than being inferred. */
#define DECL_VISIBILITY_SPECIFIED(NODE) \ #define DECL_VISIBILITY_SPECIFIED(NODE) \
(DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.visibility_specified) (DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.visibility_specified)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment