This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH,committed] Fix ICE after template declaration error(PR10583)
- From: Kriang Lerdsuwanakij <lerdsuwa at users dot sourceforge dot net>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 20 Oct 2003 19:52:29 +0700 (ICT)
- Subject: [C++ PATCH,committed] Fix ICE after template declaration error(PR10583)
- Reply-to: <lerdsuwa at users dot sourceforge dot net>
Hi
This simple patch fixes the regression PR9781, PR10583, and PR11862.
We get an error about template declaration of variable but proceed
to build a TEMPLATE_DECL around it. An error_mark_node should be
returned, rather than having later compiler stage dealing with this
erroneous case. It is fixed by the patch below.
Tested on i686-pc-linux-gnu. Committed to trunk as obvious.
--Kriang
2003-10-20 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/9781, c++/10583, c++/11862
* decl.c (cp_finish_decl): Exit immediately if decl is an
error_mark_node.
* pt.c (push_template_decl_real): Return error_mark_node for
invalid template declaration of variable.
2003-10-20 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/9781, c++/10583, c++/11862
* g++.dg/parse/crash13.C: New test.
diff -cprN gcc-main-save/gcc/cp/decl.c gcc-main-new/gcc/cp/decl.c
*** gcc-main-save/gcc/cp/decl.c Fri Oct 17 22:40:21 2003
--- gcc-main-new/gcc/cp/decl.c Sun Oct 19 20:49:59 2003
*************** cp_finish_decl (tree decl, tree init, tr
*** 4658,4664 ****
const char *asmspec = NULL;
int was_readonly = 0;
! if (! decl)
{
if (init)
error ("assignment (not initialization) in declaration");
--- 4658,4666 ----
const char *asmspec = NULL;
int was_readonly = 0;
! if (decl == error_mark_node)
! return;
! else if (! decl)
{
if (init)
error ("assignment (not initialization) in declaration");
diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c Sun Oct 19 00:34:14 2003
--- gcc-main-new/gcc/cp/pt.c Sun Oct 19 20:32:58 2003
*************** push_template_decl_real (tree decl, int
*** 2690,2696 ****
|| TREE_CODE (decl) == FUNCTION_DECL)
/* OK */;
else
! error ("template declaration of `%#D'", decl);
}
/* Check to see that the rules regarding the use of default
--- 2690,2699 ----
|| TREE_CODE (decl) == FUNCTION_DECL)
/* OK */;
else
! {
! error ("template declaration of `%#D'", decl);
! return error_mark_node;
! }
}
/* Check to see that the rules regarding the use of default
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/parse/crash13.C gcc-main-new/gcc/testsuite/g++.dg/parse/crash13.C
*** gcc-main-save/gcc/testsuite/g++.dg/parse/crash13.C Thu Jan 1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/parse/crash13.C Sun Oct 19 20:59:23 2003
***************
*** 0 ****
--- 1,22 ----
+ // { dg-do compile }
+
+ // Origin: Giovanni Bajo <giovannibajo@libero.it>
+
+ // PR c++/10583: ICE using template function with invalid signature.
+
+ template <typename>
+ struct A
+ {
+ struct B
+ {};
+ };
+
+ template <typename T>
+ void func(A<T>::B* ) // { dg-error "variable|template|expression" }
+ { // { dg-error ";" }
+ }
+
+ int main()
+ {
+ func<void>(0); // { dg-error "undeclared|expression|;" }
+ }