From 823c22f9eacdc9b5519a561eb2506d32fab41b37 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sun, 22 Jul 2007 18:46:51 +0000 Subject: [PATCH] re PR c++/32839 (internal compiler error: Segmentation fault (templates)) cp/ PR c++/32839 * typeck.c (convert_arguments): Only use default args if we have a function decl. testsuite/ PR c++/32839 * g++.dg/expr/call4.C: New. * g++.dg/expr/call5.C: New. From-SVN: r126829 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/typeck.c | 10 ++++++++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/expr/call4.C | 27 +++++++++++++++++++++++++++ gcc/testsuite/g++.dg/expr/call5.C | 19 +++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/expr/call4.C create mode 100644 gcc/testsuite/g++.dg/expr/call5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6faa01f..39da6aa 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2007-07-22 Nathan Sidwell + PR c++/32839 + * typeck.c (convert_arguments): Only use default args if we have + a function decl. + PR c++/30818 * typeck.c (structural_comptypes): No need to check resolve_typename_type return value here. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7e59ec3..7a1a725 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2885,8 +2885,14 @@ convert_arguments (int nargs, tree *argarray, if (typetail != 0 && typetail != void_list_node) { - /* See if there are default arguments that can be used. */ - if (TREE_PURPOSE (typetail) + /* See if there are default arguments that can be used. Because + we hold default arguments in the FUNCTION_TYPE (which is so + wrong), we can see default parameters here from deduced + contexts (and via typeof) for indirect function calls. + Fortunately we know whether we have a function decl to + provide default arguments in a language conformant + manner. */ + if (fndecl && TREE_PURPOSE (typetail) && TREE_CODE (TREE_PURPOSE (typetail)) != DEFAULT_ARG) { for (; typetail != void_list_node; ++i) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 17989ac..2cf110b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-07-22 Nathan Sidwell + + PR c++/32839 + * g++.dg/expr/call4.C: New. + * g++.dg/expr/call5.C: New. + 2007-07-22 Daniel Franke PR fortran/32710 diff --git a/gcc/testsuite/g++.dg/expr/call4.C b/gcc/testsuite/g++.dg/expr/call4.C new file mode 100644 index 0000000..b4f2d60 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/call4.C @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 2007 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 22 Jul 2007 + +// Origin: Danny Boelens +// PR 32839. Default arguments propagated through the type system to +// an indirect call. + +template +struct TPL +{ + enum Whatever {e1, e2}; + + static void Quux (int i = e1 | e2); +}; + +template +void DoIt (F fun) +{ + fun (); // { dg-error "too few arguments" } +} + +void Foo () +{ + DoIt (&TPL::Quux); +} diff --git a/gcc/testsuite/g++.dg/expr/call5.C b/gcc/testsuite/g++.dg/expr/call5.C new file mode 100644 index 0000000..023ad81 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/call5.C @@ -0,0 +1,19 @@ +// { dg-do compile } + +// Copyright (C) 2007 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 22 Jul 2007 + +// PR 32839. Default arguments propagated through the type system to +// an indirect call. + +void Quux (int i = 0); +void Baz (int i); + +void Foo () +{ + __typeof (Quux) *q = Baz; + + q (); // { dg-error "too few arguments" } +} + + -- 2.7.4