mirror of git://gcc.gnu.org/git/gcc.git
re PR c++/51930 (Explicitly instantiated template gets hidden visibility)
PR c++/51930 * decl2.c (determine_visibility): Correct calculation of class args depth. * decl.c (check_tag_decl): Adjust warning. From-SVN: r184946
This commit is contained in:
parent
bb828cc7f3
commit
b50530246a
|
@ -1,5 +1,10 @@
|
||||||
2012-03-05 Jason Merrill <jason@redhat.com>
|
2012-03-05 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
PR c++/51930
|
||||||
|
* decl2.c (determine_visibility): Correct calculation of class
|
||||||
|
args depth.
|
||||||
|
* decl.c (check_tag_decl): Adjust warning.
|
||||||
|
|
||||||
* method.c (synthesized_method_walk): Cleanups don't affect the EH
|
* method.c (synthesized_method_walk): Cleanups don't affect the EH
|
||||||
spec either.
|
spec either.
|
||||||
|
|
||||||
|
|
|
@ -4216,17 +4216,20 @@ check_tag_decl (cp_decl_specifier_seq *declspecs)
|
||||||
error ("%<constexpr%> cannot be used for type declarations");
|
error ("%<constexpr%> cannot be used for type declarations");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (declspecs->attributes)
|
if (declspecs->attributes && warn_attributes)
|
||||||
{
|
{
|
||||||
location_t loc = input_location;
|
location_t loc;
|
||||||
if (!CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
|
if (!CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
|
||||||
/* For a non-template class, use the name location; for a template
|
/* For a non-template class, use the name location. */
|
||||||
class (an explicit instantiation), use the current location. */
|
loc = location_of (declared_type);
|
||||||
input_location = location_of (declared_type);
|
else
|
||||||
warning (0, "attribute ignored in declaration of %q#T", declared_type);
|
/* For a template class (an explicit instantiation), use the
|
||||||
warning (0, "attribute for %q#T must follow the %qs keyword",
|
current location. */
|
||||||
declared_type, class_key_or_enum_as_string (declared_type));
|
loc = input_location;
|
||||||
input_location = loc;
|
warning_at (loc, OPT_Wattributes, "attribute ignored in declaration "
|
||||||
|
"of %q#T", declared_type);
|
||||||
|
inform (loc, "attribute for %q#T must follow the %qs keyword",
|
||||||
|
declared_type, class_key_or_enum_as_string (declared_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
return declared_type;
|
return declared_type;
|
||||||
|
|
|
@ -2181,12 +2181,8 @@ determine_visibility (tree decl)
|
||||||
? TYPE_ATTRIBUTES (TREE_TYPE (decl))
|
? TYPE_ATTRIBUTES (TREE_TYPE (decl))
|
||||||
: DECL_ATTRIBUTES (decl));
|
: DECL_ATTRIBUTES (decl));
|
||||||
|
|
||||||
if (args != error_mark_node
|
if (args != error_mark_node)
|
||||||
/* Template argument visibility outweighs #pragma or namespace
|
|
||||||
visibility, but not an explicit attribute. */
|
|
||||||
&& !lookup_attribute ("visibility", attribs))
|
|
||||||
{
|
{
|
||||||
int depth = TMPL_ARGS_DEPTH (args);
|
|
||||||
tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
|
tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo));
|
||||||
|
|
||||||
if (!DECL_VISIBILITY_SPECIFIED (decl))
|
if (!DECL_VISIBILITY_SPECIFIED (decl))
|
||||||
|
@ -2202,10 +2198,31 @@ determine_visibility (tree decl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME should TMPL_ARGS_DEPTH really return 1 for null input? */
|
if (args
|
||||||
if (args && depth > template_class_depth (class_type))
|
/* Template argument visibility outweighs #pragma or namespace
|
||||||
/* Limit visibility based on its template arguments. */
|
visibility, but not an explicit attribute. */
|
||||||
constrain_visibility_for_template (decl, args);
|
&& !lookup_attribute ("visibility", attribs))
|
||||||
|
{
|
||||||
|
int depth = TMPL_ARGS_DEPTH (args);
|
||||||
|
int class_depth = 0;
|
||||||
|
if (class_type && CLASSTYPE_TEMPLATE_INFO (class_type))
|
||||||
|
class_depth = TMPL_ARGS_DEPTH (CLASSTYPE_TI_ARGS (class_type));
|
||||||
|
if (DECL_VISIBILITY_SPECIFIED (decl))
|
||||||
|
{
|
||||||
|
/* A class template member with explicit visibility
|
||||||
|
overrides the class visibility, so we need to apply
|
||||||
|
all the levels of template args directly. */
|
||||||
|
int i;
|
||||||
|
for (i = 1; i <= depth; ++i)
|
||||||
|
{
|
||||||
|
tree lev = TMPL_ARGS_LEVEL (args, i);
|
||||||
|
constrain_visibility_for_template (decl, lev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (depth > class_depth)
|
||||||
|
/* Limit visibility based on its template arguments. */
|
||||||
|
constrain_visibility_for_template (decl, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
2012-03-05 Jason Merrill <jason@redhat.com>
|
2012-03-05 Jason Merrill <jason@redhat.com>
|
||||||
|
|
||||||
|
PR c++/51930
|
||||||
|
* g++.dg/ext/visibility/template11.C: New.
|
||||||
|
|
||||||
* g++.dg/cpp0x/implicit13.C: New.
|
* g++.dg/cpp0x/implicit13.C: New.
|
||||||
|
|
||||||
2012-03-05 Jakub Jelinek <jakub@redhat.com>
|
2012-03-05 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
// PR c++/51930
|
||||||
|
// { dg-require-visibility "" }
|
||||||
|
// { dg-options "-fvisibility=hidden" }
|
||||||
|
// { dg-final { scan-not-hidden "_ZN13template_testI4testE8functionEv" } }
|
||||||
|
|
||||||
|
struct test { };
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct template_test
|
||||||
|
{
|
||||||
|
__attribute__((visibility("default")))
|
||||||
|
void function();
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void template_test<T>::function() { }
|
||||||
|
|
||||||
|
template
|
||||||
|
struct __attribute__((visibility("default")))
|
||||||
|
template_test<test>;
|
Loading…
Reference in New Issue