Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2003-01-24 22:30:45


On Friday, January 24, 2003, at 09:36 PM, David Abrahams wrote:

> Howard Hinnant <hinnant_at_[hidden]> writes:
>
>> Fortunately circumstances such as the one illustrated
>> above seem to be rare (at least in my experience). But
>> it is amusing (amazing?) how many traits like tests are
>> today passing non-POD classes to an ellipsis, and
>> invoking undefined behavior! :-)
>
> I thought there wansn't any undefined behavior there, because none of
> the traits actually generate or execute the code within sizeof(). I
> can understand it being unspecified whether you get an error due to
> accessibility of the c-ctor. Am I misunderstanding how the standard
> works in this area?

Expressions in sizeof are accessed checked:

class B
{
        int foo();
};

int main()
{
        B b;
        unsigned i = sizeof(b.foo()); // error, foo() not accessible
}

Furthermore, it is undefined to pass a non-pod to an ellipse (5.2.2/7):

int foo(...);

class B
{
public:
        B();
private:
        B(const B&);
};

int main()
{
        foo(B()); // undefined behavior
}

If you stick that in a sizeof, it is still undefined:

        sizeof(foo(B()));

If you overload foo, it is still undefined:

int foo(...);
char foo(int);

At least, that is my current understanding.

Note that I am not saying that traits using ellipses are not a good
thing. I'm just exposing a non-portable corner.

-Howard


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