From c76a22fb619cc0a424ab5caa27104c163f069e37 Mon Sep 17 00:00:00 2001 From: mmitchel Date: Mon, 12 Mar 2007 16:24:18 +0000 Subject: [PATCH] PR c++/30108 * call.c (convert_default_arg): Copy non-constant arguments. PR c++/30108 * g++.dg/other/default6.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@122844 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 10 +++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/other/default6.C | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/default6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index acc64352947e..ccbb842d2fe3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2007-03-12 Mark Mitchell + + PR c++/30108 + * call.c (convert_default_arg): Copy non-constant arguments. + 2007-03-11 Mark Mitchell PR c++/31038 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 637671bc1bcb..00e0c063e862 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4664,10 +4664,14 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum) } else { - /* This could get clobbered by the following call. */ - if (TREE_HAS_CONSTRUCTOR (arg)) + /* We must make a copy of ARG, in case subsequent processing + alters any part of it. For example, during gimplification a + cast of the form (T) &X::f (where "f" is a member function) + will lead to replacing the PTRMEM_CST for &X::f with a + VAR_DECL. We can avoid the copy for constants, since they + are never modified in place. */ + if (!CONSTANT_CLASS_P (arg)) arg = copy_node (arg); - arg = convert_for_initialization (0, type, arg, LOOKUP_NORMAL, "default argument", fn, parmnum); arg = convert_for_arg_passing (type, arg); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2c3f7d8dcb41..9d0a8df6333a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-03-12 Mark Mitchell + + PR c++/30108 + * g++.dg/other/default6.C: New test. + 2007-03-12 Richard Sandiford * lib/target-supports.exp (check_profiling_available): Return false diff --git a/gcc/testsuite/g++.dg/other/default6.C b/gcc/testsuite/g++.dg/other/default6.C new file mode 100644 index 000000000000..2641801b1e4f --- /dev/null +++ b/gcc/testsuite/g++.dg/other/default6.C @@ -0,0 +1,18 @@ +// PR c++/30108 + +class BaseRobot { + typedef void (BaseRobot::*PseudoState)(void); + typedef PseudoState STATE; + STATE initial (); + int ready (); + STATE stpOtherTask (); + STATE commonEventProcessing (STATE pIdleTarget=(STATE)&BaseRobot::ready); +}; +BaseRobot::STATE BaseRobot::initial () +{ + return commonEventProcessing (); +} +BaseRobot::STATE BaseRobot::stpOtherTask () +{ + return commonEventProcessing (); +} -- 2.47.3