Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2002-08-02 13:59:01


On Fri, 2 Aug 2002 21:28:05 +0300, "Peter Dimov" <pdimov_at_[hidden]>
wrote:

[...]
>
>Compiler bug/extension; there are compilers that diagnose it. To see that
>it's a bug, add this:
>
>> int
>> foo(int a = 1, int b = 2)
>> { return a + b; }
>
>int foo2(int a = -1, int b = -2) { return a + b; }
>
>> ///////////////////////////////////////
>> int
>> main()
>> {
>> typedef f_stubs<int(int a, int b)> f_stubs;
>>
>> cout << f_stubs::f0(foo) () << endl;
> cout << f_stubs::f0(foo2) () << endl;
>> }

AFAIK this is one of the more widespread bug in C++ implementations.
When you give two functions of the same type, like in Peter's example,
there are compilers which fail to link and others that link but use
the same default arguments used for the first call (in the example, 1
and 2). Here's a simpler example:

  template <typename pointerT>
  inline void call_it(pointerT p)
  {
    (*p)();
  }

  void f(int i = 0) { cout << i << '\n'; }
  void f2 (int i = 5) { cout << i << '\n'; }

  int main ()
  {
    call_it(&f);
    call_it(&f2);
  }

I wonder if there's any easy workaround.

Genny.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk