aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/pt.c
diff options
context:
space:
mode:
authorSimon Baldwin <simonb@google.com>2007-06-18 22:09:14 +0000
committerSimon Baldwin <simonb@gcc.gnu.org>2007-06-18 22:09:14 +0000
commit736b81007e965d4d1141dca6e45837d756741ddb (patch)
treeebe83019aac080d1a8f2fefc14cab3473f2d4579 /gcc/cp/pt.c
parentd448952a83fa71a5658c2f775e7c86316821f4fe (diff)
downloadgcc-736b81007e965d4d1141dca6e45837d756741ddb.zip
gcc-736b81007e965d4d1141dca6e45837d756741ddb.tar.gz
gcc-736b81007e965d4d1141dca6e45837d756741ddb.tar.bz2
re PR c++/31923 (g++ accepts a storage-class-specifier on a template explicit specialization)
gcc/cp/ChangeLog 2007-06-15 Simon Baldwin <simonb@google.com> 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 <simonb@google.com> PR c++/31923 * g++.dg/template/error25.C: New. * g++.dg/template/spec35.C: New. From-SVN: r125829
Diffstat (limited to 'gcc/cp/pt.c')
-rw-r--r--gcc/cp/pt.c31
1 files changed, 31 insertions, 0 deletions
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: