Re: Porting GCC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 10 Sept 2025, 04:49 Xi Ruoyao wrote:
>
> On Tue, 2025-09-09 at 23:45 +0200, Arsen Arsenović via Gcc-help wrote:
> > We claim to be able to build using an ISO C++14 compiler, though (and
> > presumably a C compiler of similar age), so perhaps we shouldn't use
> > alloca.
>
> The claim is not fully true anyway... for example we perform narrowing
> conversions from constant, but C++14 does not allow to do so.

Could you give an example in the GCC source where that's the case?

C++14 allows narrowing from constants if the value fits in the
destination type, and requires a diagnostic if the value doesn't fit.
GCC conforms, allowing the former case and giving an error for the
latter:

const int i = 42;
char c{i};  // not narrowing
char x{i * i};

narrow.cc:3:10: error: narrowing conversion of ‘1764’ from ‘int’ to
‘char’ [-Wnarrowing]
   3 | char x{i * i};
     |        ~~^~~

So I don't think the problem you described can happen.

C++14 does not allow it for a **non-constant**, and GCC warns in that case:

int i = 42;  // not const
char c{i};

arrow.cc:2:8: warning: narrowing conversion of ‘i’ from ‘int’ to
‘char’ [-Wnarrowing]
   2 | char c{i};
     |        ^

Maybe you're thinking of cases like this, where a non-constant is narrowed?

That is not allowed by C++14 and we should insert the necessary casts
(and build state1 with -Werror=narrowing).




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux