This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Fix PR c++/20172: Invalid non-type template parametersnot diagnosed
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 12 Jul 2005 17:09:10 +0100
- Subject: Re: [patch] Fix PR c++/20172: Invalid non-type template parametersnot diagnosed
- References: <200506100955.j5A9tNDS017925@relay.rwth-aachen.de> <42A9C00E.8050605@codesourcery.com> <200506112355.j5BNt2ik026352@relay.rwth-aachen.de>
Volker Reichelt wrote:
2005-06-10 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/20172
* pt.c (tsubst_template_parms): Check for invalid non-type parameters.
===================================================================
--- gcc/gcc/cp/pt.c 2005-04-08 21:36:01.000000000 +0200
+++ gcc/gcc/cp/pt.c 2005-06-09 01:13:03.000000000 +0200
@@ -5962,6 +5962,9 @@ tsubst_template_parms (tree parms, tree
tree parm_decl = TREE_VALUE (tuple);
parm_decl = tsubst (parm_decl, args, complain, NULL_TREE);
+ if (TREE_CODE (parm_decl) != TEMPLATE_DECL)
+ invalid_nontype_parm_type_p (TREE_TYPE (parm_decl), complain);
+
default_value = tsubst_template_arg (default_value, args,
complain, NULL_TREE);
this isn't quite right, template type parms also go through here. I fixed the
test, and committed the attached patch after testing. thanks for looking at this.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2005-07-12 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Nathan Sidwell <nathan@codesourcery.com>
PR c++/20172
* pt.c (tsubst_template_parms): Check for invalid non-type parameters.
2005-07-12 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/20172
* g++.dg/template/nontype12.C : New test.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.1014
diff -c -3 -p -r1.1014 pt.c
*** cp/pt.c 8 Jul 2005 23:37:01 -0000 1.1014
--- cp/pt.c 12 Jul 2005 11:12:37 -0000
*************** tsubst_template_parms (tree parms, tree
*** 5987,5992 ****
--- 5987,5995 ----
tree parm_decl = TREE_VALUE (tuple);
parm_decl = tsubst (parm_decl, args, complain, NULL_TREE);
+ if (TREE_CODE (parm_decl) == PARM_DECL
+ && invalid_nontype_parm_type_p (TREE_TYPE (parm_decl), complain))
+ parm_decl = error_mark_node;
default_value = tsubst_template_arg (default_value, args,
complain, NULL_TREE);
Index: testsuite/g++.dg/template/nontype12.C
===================================================================
RCS file: testsuite/g++.dg/template/nontype12.C
diff -N testsuite/g++.dg/template/nontype12.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/nontype12.C 12 Jul 2005 11:12:29 -0000
***************
*** 0 ****
--- 1,35 ----
+ // PR c++/20172
+ // Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
+
+ template<typename T> struct A
+ {
+ template<T> int foo(); // { dg-error "double" }
+ template<template<T> class> int bar(); // { dg-error "double" }
+ template<T> struct X; // { dg-error "double" }
+ };
+
+ A<char> a1;
+ A<double> a2; // { dg-error "instantiated" }
+
+ template<typename T> struct B
+ {
+ template<double> int foo(); // { dg-error "double" }
+ template<template<double> class> int bar(); // { dg-error "double" }
+ template<double> struct X; // { dg-error "double" }
+ };
+
+ template<void> int foo(); // { dg-error "void" }
+ template<template<void> class> int bar(); // { dg-error "void" }
+ template<void> struct X; // { dg-error "void" }
+
+ template<typename T> struct C
+ {
+ template<T> int foo(); // { dg-error "double" }
+ };
+
+ template<typename T> int baz(T) { C<T> c; } // { dg-error "instantiated" }
+
+ void foobar()
+ {
+ baz(1.2); // { dg-error "instantiated" }
+ }