This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH,committed] Fix PR12403 (explicit specialization innon-namespace scope)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 29 Dec 2003 17:25:48 +0700 (ICT)
- Subject: [C++ PATCH,committed] Fix PR12403 (explicit specialization innon-namespace scope)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
In cp_parser_template_declaration_after_export, we didn't properly
record that a 'template <>', although not valid here, is a
specialization scope 'sk_template_spec'. This confuses later
diagnosis and processing, such as 'check_explicit_specialization'.
With the patch, the type of template header is correctly recorded.
This fixes the ICE reported as PR12403 which is a regression in 3.4
and restores the 'explicit specialization in non-namespace scope'
diagnostics produced by GCC 3.3.x.
Tested on i686-pc-linux-gnu. Committed to the mainline as obvious.
--Kriang
2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/12403
* parser.c (cp_parser_template_declaration_after_export): Set up
template specialization scope in case of explicit specialization.
2003-12-29 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/12403
* g++.dg/parse/explicit1.C: New test.
* g++.old-deja/g++.pt/explicit71.C: Adjust expected error.
diff -cprN gcc-main-save/gcc/cp/parser.c gcc-main-new/gcc/cp/parser.c
*** gcc-main-save/gcc/cp/parser.c Thu Dec 18 21:09:31 2003
--- gcc-main-new/gcc/cp/parser.c Sun Dec 28 19:11:15 2003
*************** cp_parser_template_declaration_after_exp
*** 13961,13979 ****
if (!cp_parser_require (parser, CPP_LESS, "`<'"))
return;
- /* Parse the template parameters. */
- begin_template_parm_list ();
/* If the next token is `>', then we have an invalid
specialization. Rather than complain about an invalid template
parameter, issue an error message here. */
if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER))
{
cp_parser_error (parser, "invalid explicit specialization");
parameter_list = NULL_TREE;
}
else
! parameter_list = cp_parser_template_parameter_list (parser);
! parameter_list = end_template_parm_list (parameter_list);
/* Look for the `>'. */
cp_parser_skip_until_found (parser, CPP_GREATER, "`>'");
/* We just processed one more parameter list. */
--- 13961,13983 ----
if (!cp_parser_require (parser, CPP_LESS, "`<'"))
return;
/* If the next token is `>', then we have an invalid
specialization. Rather than complain about an invalid template
parameter, issue an error message here. */
if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER))
{
cp_parser_error (parser, "invalid explicit specialization");
+ begin_specialization ();
parameter_list = NULL_TREE;
}
else
! {
! /* Parse the template parameters. */
! begin_template_parm_list ();
! parameter_list = cp_parser_template_parameter_list (parser);
! parameter_list = end_template_parm_list (parameter_list);
! }
!
/* Look for the `>'. */
cp_parser_skip_until_found (parser, CPP_GREATER, "`>'");
/* We just processed one more parameter list. */
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/parse/explicit1.C gcc-main-new/gcc/testsuite/g++.dg/parse/explicit1.C
*** gcc-main-save/gcc/testsuite/g++.dg/parse/explicit1.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/parse/explicit1.C Sun Dec 28 19:09:03 2003
***************
*** 0 ****
--- 1,11 ----
+ // { dg-do compile }
+
+ // Origin: stefaandr@hotmail.com
+
+ // PR c++/12403: ICE when explicit specialization is not in
+ // namespace scope.
+
+ struct foo {
+ template<typename T> void bar (T &t) {}
+ template<> void bar<double>(double &t) {} // { dg-error "explicit|non-namespace|member" }
+ };
diff -cprN gcc-main-save/gcc/testsuite/g++.old-deja/g++.pt/explicit71.C gcc-main-new/gcc/testsuite/g++.old-deja/g++.pt/explicit71.C
*** gcc-main-save/gcc/testsuite/g++.old-deja/g++.pt/explicit71.C Thu May 1 18:35:25 2003
--- gcc-main-new/gcc/testsuite/g++.old-deja/g++.pt/explicit71.C Sun Dec 28 21:09:22 2003
*************** class bug {
*** 12,15 ****
};
template <class X>
template <> // { dg-error "" } invalid specialization
! class bug<X>::a<char> {};
--- 12,15 ----
};
template <class X>
template <> // { dg-error "" } invalid specialization
! class bug<X>::a<char> {}; // { dg-error "" }