[cfe-commits] r149286 - in /cfe/trunk: lib/AST/ExprConstant.cpp lib/Sema/SemaOverload.cpp test/CXX/expr/expr.const/p2-0x.cpp

Eli Friedman eli.friedman at gmail.com
Mon Jan 30 18:22:34 PST 2012


On Mon, Jan 30, 2012 at 6:01 PM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Mon, Jan 30, 2012 at 4:29 PM, Eli Friedman <eli.friedman at gmail.com>
> wrote:
>>
>> On Mon, Jan 30, 2012 at 2:27 PM, Richard Smith
>> <richard-llvm at metafoo.co.uk> wrote:
>> > Author: rsmith
>> > Date: Mon Jan 30 16:27:01 2012
>> > New Revision: 149286
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=149286&view=rev
>> > Log:
>> > constexpr: disallow signed integer overflow in integral conversions in
>> > constant
>> > expressions in C++11.
>>
>> Standard citation?  As far as I can tell, the result of
>> (int)0x80000000u is implementation-defined, but it's still a constant
>> expression given how we define it.
>
>
> Oops, r149327. This was (incorrectly) factored out of another change which
> I'm still questioning... Consider:
>
>   enum E { n = 2 };
>   E e = (E)5;
>
> 5 is not in the range of values of the enumeration (which is 0..3 by
> [dcl.enum]p7), but is clearly in the underlying type. Is this value in the
> range of representable values for its type (or is this undefined behavior by
> [expr]p4)?

I think the relevant passage is actually [expr.static.cast]p10:

A value of integral or enumeration type can be explicitly converted to
an enumeration type. The value is unchanged if the original value is
within the range of the enumeration values (7.2). Otherwise, the
resulting value is unspecified (and might not be in that range).


That doesn't sound like undefined behavior to me.

-Eli




More information about the cfe-commits mailing list