@@ -2903,8 +2903,8 @@ extern void decl_value_expr_insert (tree, tree);
#define DECL_VISIBILITY(NODE) \
(DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.visibility)
-/* Nonzero means that the decl had its visibility specified rather than
- being inferred. */
+/* Nonzero means that the decl (or an enclosing scope) had its
+ visibility specified rather than being inferred. */
#define DECL_VISIBILITY_SPECIFIED(NODE) \
(DECL_WITH_VIS_CHECK (NODE)->decl_with_vis.visibility_specified)
@@ -2629,6 +2629,7 @@ determine_visibility (tree decl)
tree attribs = (TREE_CODE (decl) == TYPE_DECL
? TYPE_ATTRIBUTES (TREE_TYPE (decl))
: DECL_ATTRIBUTES (decl));
+ tree attr = lookup_attribute ("visibility", attribs);
if (args != error_mark_node)
{
@@ -2636,7 +2637,7 @@ determine_visibility (tree decl)
if (!DECL_VISIBILITY_SPECIFIED (decl))
{
- if (!DECL_VISIBILITY_SPECIFIED (pattern)
+ if (!attr
&& determine_hidden_inline (decl))
DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN;
else
@@ -2650,7 +2651,7 @@ determine_visibility (tree decl)
if (args
/* Template argument visibility outweighs #pragma or namespace
visibility, but not an explicit attribute. */
- && !lookup_attribute ("visibility", attribs))
+ && !attr)
{
int depth = TMPL_ARGS_DEPTH (args);
if (DECL_VISIBILITY_SPECIFIED (decl))
new file mode 100644
@@ -0,0 +1,13 @@
+// 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>();
+}