[cfe-dev] C++ Conditional Operator

Sebastian Redl sebastian.redl at getdesigned.at
Mon Apr 13 09:14:10 PDT 2009


Eli Friedman wrote:
> On Sun, Apr 12, 2009 at 2:33 PM, Sebastian Redl
> <sebastian.redl at getdesigned.at> wrote:
>   
>> I'll implement C++ semantics for ?: over the next few days. Because the
>> operator has awful semantics, I've decided to use a test-first approach
>> to it. I'd appreciate a review of my test case before I go and implement
>> something incorrect.
>>     
>
> For the bit-fields, a test like "(i1 ? flds.b1 : flds.b2) = 0;" would be nice.
>   

Doh! Of course I can test lvalue-ness of bitfields by assigning.

Hmm ... is it specified anywhere what this snippet does?

struct { unsigned a : 3, b: 5; } fields;
(coinflip() ? fields.a : fields.b) = 10;

Does some sort of size unification happen between the two bitfields, or
are the semantics exactly the same as

if(coinflip()) fields.a = 10; else fields.b = 10;

?

> For the p2 tests, a test that should fail like "1 ? (void)0 : 0;" would be nice.
>   

Mixing void and non-void; good catch.

> For the p3 tests, one or two tests with private bases might be useful,
> to make sure we're actually finding the right conversion.
>
>   

True. Also, ambiguous bases.

Thanks,
Sebastian



More information about the cfe-dev mailing list