From 736b81007e965d4d1141dca6e45837d756741ddb Mon Sep 17 00:00:00 2001 From: Simon Baldwin Date: Mon, 18 Jun 2007 22:09:14 +0000 Subject: re PR c++/31923 (g++ accepts a storage-class-specifier on a template explicit specialization) gcc/cp/ChangeLog 2007-06-15 Simon Baldwin PR c++/31923 * parser.c (cp_parser_single_declaration): Added check for storage class other than sc_none in parsed declaration, and a flag to indicate if the call is part of an explicit template specialization parse. * (cp_parser_explicit_specialization): Specialization check flag added to call to cp_parser_single_declaration(), set true. * (cp_parser_template_declaration_after_export): Specialization check flag added to call to cp_parser_single_declaration(), set false. * pt.c (check_explicit_specialization): Added code to copy visiblity and linkage from the templated function to the explicit specialization. gcc/testsuite/ChangeLog 2007-06-15 Simon Baldwin PR c++/31923 * g++.dg/template/error25.C: New. * g++.dg/template/spec35.C: New. From-SVN: r125829 --- gcc/cp/pt.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gcc/cp/pt.c') diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index f3210dd..63f8247 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2193,6 +2193,37 @@ check_explicit_specialization (tree declarator, TREE_PRIVATE (decl) = TREE_PRIVATE (gen_tmpl); TREE_PROTECTED (decl) = TREE_PROTECTED (gen_tmpl); + /* 7.1.1-1 [dcl.stc] + + A storage-class-specifier shall not be specified in an + explicit specialization... + + The parser rejects these, so unless action is taken here, + explicit function specializations will always appear with + global linkage. + + The action recommended by the C++ CWG in response to C++ + defect report 605 is to make the storage class and linkage + of the explicit specialization match the templated function: + + http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#605 + */ + if (tsk == tsk_expl_spec && DECL_FUNCTION_TEMPLATE_P (gen_tmpl)) + { + tree tmpl_func = DECL_TEMPLATE_RESULT (gen_tmpl); + gcc_assert (TREE_CODE (tmpl_func) == FUNCTION_DECL); + + /* This specialization has the same linkage and visiblity as + the function template it specializes. */ + TREE_PUBLIC (decl) = TREE_PUBLIC (tmpl_func); + DECL_THIS_STATIC (decl) = DECL_THIS_STATIC (tmpl_func); + if (DECL_VISIBILITY_SPECIFIED (tmpl_func)) + { + DECL_VISIBILITY_SPECIFIED (decl) = 1; + DECL_VISIBILITY (decl) = DECL_VISIBILITY (tmpl_func); + } + } + /* If DECL is a friend declaration, declared using an unqualified name, the namespace associated with DECL may have been set incorrectly. For example, in: -- cgit v1.1