This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix PR c++/15759: Function pointers in default arguments

On 17 Jun, Nathan Sidwell wrote:
> Volker Reichelt wrote:
>   tree.c (bot_manip): See through CONVERT_EXPR correctly.
>> ===================================================================
>> --- gcc/gcc/cp/tree.c	15 Jun 2005 00:41:34 -0000	1.437
>> +++ gcc/gcc/cp/tree.c	16 Jun 2005 16:58:47 -0000
>> @@ -1181,7 +1181,12 @@ bot_manip (tree* tp, int* walk_subtrees,
>>        return NULL_TREE;
>>      }
>>    else if (TREE_CODE (t) == CALL_EXPR)
>> -    mark_used (TREE_OPERAND (TREE_OPERAND (t, 0), 0));
>> +    {
>> +      t = TREE_OPERAND (t, 0);
>> +      if (TREE_CODE (t) == CONVERT_EXPR)
>> +        t = TREE_OPERAND (t, 0);
>> +      mark_used (t);
>> +    }
> this will only catch the case you found.  the default arg could be something 
> arbitrary like
> int (*ptr_ary[10])();
>    void foo (int arg = ptr_ary[somecall()] ());

This already works with current releases. Looks like the recursion between
bot_manip and break_out_target_exprs works fine.

> I'm not sure if we still have to call mark_used here anyway -- I think we'll 
> have called it when parsing the default arg anyway -- can you try not doing that?

I'm not sure how to test reliably that we don't need mark_used.
Do you have a suggestion for a testcase?

I tried the following test which worked fine (no linker failures)
when I ripped out the call to mark_used:

    static int (*PTR)();
    template<typename T> void foo(T = PTR()) {}
    struct A {};
    int main()
        return 0;

And also no traces of PTR in the assembly, if I comment out foo<int>(); .

So you may indeed have a point here.
Btw, there's another call to mark_used in bot_manip. What about that one?
I'll try a bootstrap tonight with both calls ripped out.

However, the testsuite coverage for default arguments is very small and
I'm not familiar enough with the internals to decide whether it's safe to
rip it out entirely. Therefore I'd rather go with the more conservative
method I proposed.

But, of course, feel free to rip it out if you consider this safe.

> If it turns out we do need to call it, I think it would be safe to call 
> mark_used on any _DECL node passed into bot_manip.

I'm not quite following you here.
Is that necessary given that your exmaple above compiles fine?

> [I realise I've forgotten about your template patch, adding it to my documented 
> todo-list now.]


> nathan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]