Subject: Re: 2006Q1 audio/audacity fails to build on 3.0/amd64
To: Martin Husemann <martin@duskware.de>
From: Rhialto <rhialto@falu.nl>
List: pkgsrc-users
Date: 04/06/2006 01:43:30
On Thu 06 Apr 2006 at 00:54:29 +0200, Martin Husemann wrote:
> Because C++ should not require any casts from NULL to other pointer types.

Normally not perhaps, but if it disambiguates an ambiguous function
call, it may help.

> If this realy is a reference, of course this does not apply and instead the
> authors of the code should be mistreaded very badly.

No the authors don't mean to call the function with the reference
parameter. But the compiler doesn't know that.

Let's analyse the necessary conversions for both overloaded functions.
The actual parameters are

   wxChoice *item4 = new wxChoice(parent, 10001, wxDefaultPosition,
                                     wxSize(80, -1), 0, __null);

The first 4 are not in dispute: they are the same in both functions.
The problem is in 0, NULL, which should I think, behave as 0, 0.

So, matching them on 

            int n = 0, const wxString choices[] = (const wxString *) __null, 

will be no problem.

Matching them on 

            const wxArrayString& choices,
	    long style = 0,

will also work, since there is a constructor that makes an int into a
wxArrayString:

  wxArrayString(int autoSort) { Init(autoSort != 0); }

and then a reference can be taken to the temporary object[1]. Of course
this is not what the author of the code intends, but the compiler cannot
know that.

So there are two possible functions to call. To take away this
ambiguity, the NULL (0, or __null) should be make more explicit, and it
removes the second interpretation.

[1] To illustrate that g++ does consider this a valid conversion:

class Class {
public:
    Class(int i) {};
};

void func(const Class &c)
{
}

int
main(int argc, char **argv)
{
    func(0);

    return 0;
}

Take away the const and g++ will complain:
c.cc:13: error: invalid initialization of non-const reference of type
'Class&' from a temporary of type 'int'

Trying out this variation:

class Class {
public:
    Class(int i) {};
};

void bar(int i, char *p)
{
}

void bar(const Class &c, long l)
{
}

int
main(int argc, char **argv)
{
    bar(0, 0);
    //bar(0, __null);
    bar(0, (char *)__null);

    return 0;
}

it seems that g++ only complains about the middle, commented call.
Apparently it feels the need to be pedantic, despite the fact that
somebody wrote NULL which might mean to indicate the first bar()
function. I would personally have hoped for the same pedantry about the
first call. But since, on amd64 NULL is __null I do get the error, and
since on i386 it is 0, people there don't get the error.

> Martin
-Olaf.
-- 
___ Olaf 'Rhialto' Seibert      -- You author it, and I'll reader it.
\X/ rhialto/at/xs4all.nl        -- Cetero censeo "authored" delendum esse.