From 2c05d05ede8e14d8e709b172e83004c53fb30187 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 4 Dec 2006 18:08:11 +0000 Subject: [PATCH] re PR c++/29733 (ICE on initialization of function type) PR c++/29733 * pt.c (tsubst_decl): Disallow variables of function type. PR c++/29733 * g++.dg/template/crash61.C: New test. From-SVN: r119500 --- gcc/cp/ChangeLog | 3 +++ gcc/cp/pt.c | 21 +++++++++++++++++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/template/crash61.C | 11 +++++++++++ 4 files changed, 38 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/crash61.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a4c1a113262..f0f93c0e40c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2006-12-04 Mark Mitchell + PR c++/29733 + * pt.c (tsubst_decl): Disallow variables of function type. + PR c++/29632 * call.c (add_builtin_candidate): Do not permit NULL pointer constants to be compared with template parameters. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0b8eecac3ff..acaf6bce00f 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -6954,6 +6954,27 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) type = tsubst (TREE_TYPE (t), args, complain, in_decl); if (type == error_mark_node) return error_mark_node; + if (TREE_CODE (type) == FUNCTION_TYPE) + { + /* It may seem that this case cannot occur, since: + + typedef void f(); + void g() { f x; } + + declares a function, not a variable. However: + + typedef void f(); + template void g() { T t; } + template void g(); + + is an attempt to declare a variable with function + type. */ + error ("variable %qD has function type", + /* R is not yet sufficiently initialized, so we + just use its name. */ + DECL_NAME (r)); + return error_mark_node; + } type = complete_type (type); DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (r) = DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (t); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3e0e6412e4f..0d558084d4a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2006-12-04 Mark Mitchell + PR c++/29733 + * g++.dg/template/crash61.C: New test. + PR c++/29632 * g++.dg/template/error23.C: New test. diff --git a/gcc/testsuite/g++.dg/template/crash61.C b/gcc/testsuite/g++.dg/template/crash61.C new file mode 100644 index 00000000000..1f70bcb89d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash61.C @@ -0,0 +1,11 @@ +// PR c++/29733 + +template void foo() +{ + T t = 0; // { dg-error "function type" } +} + +void bar() +{ + foo(); +} -- 2.30.2