[patch] Fix PR c++/25854: Bogus diagnostic with '<type error>'
Volker Reichelt
reichelt@igpm.rwth-aachen.de
Thu Jan 19 10:42:00 GMT 2006
For the testcase
template<typename> struct A {};
template<> struct A<> {};
we issue the following diagnostic:
diag.cc:2: error: wrong number of template arguments (0, should be 1)
diag.cc:1: error: provided for 'template<class> struct A'
diag.cc:2: error: explicit specialization of non-template '<type error>'
The third line (which wasn't emitted before GCC 3.4.0) is clearly bogus.
This happens because we pass an error_mark_node as argument to
maybe_process_partial_specialization, which cannot do anything
useful with this input and gives this bogus diagnostic.
The fix is to return early on such input.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline, 4.1 branch, 4.0 branch, and 3.4 branch?
Regards,
Volker
:ADDPATCH C++:
2006-01-19 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/25854
* pt.c (maybe_process_partial_specialization): Return early on
error_mark_node.
====================================================================
--- gcc/gcc/cp/pt.c 2006-01-07 21:26:41 +0100
+++ gcc/gcc/cp/pt.c 2006-01-07 21:24:52 +0100
@@ -678,8 +678,12 @@ check_explicit_instantiation_namespace (
void
maybe_process_partial_specialization (tree type)
{
- /* TYPE maybe an ERROR_MARK_NODE. */
- tree context = TYPE_P (type) ? TYPE_CONTEXT (type) : NULL_TREE;
+ tree context;
+
+ if (type == error_mark_node)
+ return;
+
+ context = TYPE_CONTEXT (type);
if (CLASS_TYPE_P (type) && CLASSTYPE_USE_TEMPLATE (type))
{
====================================================================
2006-01-19 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/25854
* g++.dg/template/spec28.C: New test.
====================================================================
--- gcc/gcc/testsuite/g++.dg/template/spec28.C 2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/g++.dg/template/spec28.C 2006-01-09 18:48:42 +0100
@@ -0,0 +1,6 @@
+// PR c++/25854
+// Bad diagnostic
+// { dg-do compile }
+
+template<typename> struct A {}; // { dg-error "provided" }
+template<> struct A<> {}; // { dg-error "wrong number" }
====================================================================
More information about the Gcc-patches
mailing list