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

Abramo Bagnara abramo.bagnara at gmail.com
Tue Jan 31 00:40:36 PST 2012


Il 31/01/2012 03:22, Eli Friedman ha scritto:
> 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.

Yes, you're definitely right from a standard point of view, but using
the point of view of constant evaluator, does it make a difference?

I.e., the conversion of an integer out of enum range specified by
[decl.enum]p7 to that enum type should be a known constant?

I don't think so, but I'd like to hear your opinion.

-- 
Abramo Bagnara

Opera Unica                          Phone: +39.0546.656023
Via Borghesi, 16
48014 Castel Bolognese (RA) - Italy



More information about the cfe-commits mailing list