[patch] Fix PR c++/28111: ICE with invalid friend in template class
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Wed Jun 21 11:13:00 GMT 2006
The C++ frontend ICEs on the following invalid code snippet:
template<typename> void foo();
template<typename T> struct A
{
friend void foo<>(typename T::X);
};
A<int> a;
bug.cc: In instantiation of 'A<int>':
bug.cc:8: instantiated from here
bug.cc:5: error: 'int' is not a class, struct, or union type
bug.cc:5: internal compiler error: tree check: expected function_type or method_type, have error_mark in determine_specialization, at cp/pt.c:1396
Please submit a full bug report, [etc.]
We already have a sanity check at the beginning of determine_specialization.
But it only checks the first argument and not the seocond for
error_mark_nodes. The patch fixes the ICE by also checking the
second argument.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline?
Regards,
Volker
:ADDPATCH C++:
2006-06-21 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28111
* pt.c (determine_specialization): Check for invalid decls.
===================================================================
--- gcc/gcc/cp/pt.c (revision 114800)
+++ gcc/gcc/cp/pt.c (working copy)
@@ -1354,7 +1354,7 @@ determine_specialization (tree template_id,
*targs_out = NULL_TREE;
- if (template_id == error_mark_node)
+ if (template_id == error_mark_node || decl == error_mark_node)
return error_mark_node;
fns = TREE_OPERAND (template_id, 0);
===================================================================
2006-06-21 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28111
* g++.dg/template/friend43.C: New test.
===================================================================
--- gcc/gcc/testsuite/g++.dg/template/friend43.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/friend43.C 2006-06-20 18:54:35 +0200
@@ -0,0 +1,11 @@
+// PR c++/28111
+// { dg-do compile }
+
+template<typename> void foo();
+
+template<typename T> struct A
+{
+ friend void foo<>(typename T::X); // { dg-error "not a class" }
+};
+
+A<int> a;
===================================================================
More information about the Gcc-patches
mailing list