C++ Logo

std-proposals

Advanced search

Re: [std-proposals] D3666R0 Bit-precise integers

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Wed, 10 Sep 2025 20:44:19 +0200
On 9/10/25 20:18, Jan Schultke wrote:
>> int i = 0;
>> unsigned int x[] = { 0, // ok, because constant
>> i }; // error: narrowing
>>
>> If we wish to make certain initializations (e.g. copy-initialization of
>> certain types) narrowing-detecting, we have precedent for that.
>
> Do we have an example that is not within list-initialization? To my
> understanding, narrowing detection outside list-initialization would
> be unprecedented.


[expr.spaceship]

"If a narrowing conversion (9.5.5) is required, other than from an integral type to a floating-point type,
the program is ill-formed."


[expr.const] p21

"A converted constant expression of type T is an expression, implicitly converted to type T, where the converted
expression is a constant expression and the implicit conversion sequence contains only
...
integral conversions (7.3.9) other than narrowing conversions (9.5.5),
...
"


Jens

Received on 2025-09-10 18:44:22