diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-12-04 18:08:11 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-12-04 18:08:11 +0000 |
commit | 729a26ca737cc04301584a808a09866752d192e3 (patch) | |
tree | 64d0f23d27b0b2b14eb52109511cf8201f0d3f7b /gcc/cp | |
parent | d3d4beab4467b0c73d70d537f5449753555422f2 (diff) | |
download | gcc-729a26ca737cc04301584a808a09866752d192e3.tar.gz |
PR c++/29733
* pt.c (tsubst_decl): Disallow variables of function type.
PR c++/29733
* g++.dg/template/crash61.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119500 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/pt.c | 21 |
2 files changed, 24 insertions, 0 deletions
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 <mark@codesourcery.com> + 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 <typename T> void g() { T t; } + template void g<f>(); + + 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); |