Bug 1803333 - Regression in -Wnarrowing on 32bit (GCC10)
Summary: Regression in -Wnarrowing on 32bit (GCC10)
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-02-15 09:58 UTC by Igor Raits
Modified: 2020-10-05 08:30 UTC (History)
11 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-02-15 10:32:45 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Igor Raits 2020-02-15 09:58:20 UTC
With latest rawhide glibc/gcc, the fish started to be FTBFS.

See https://github.com/fish-shell/fish-shell/issues/6609 for more details.

../src/wutil.cpp: In function 'int fd_check_is_remote(int)':
../src/wutil.cpp:311:14: error: narrowing conversion of '4283649346' from 'unsigned int' to 'int' [-Wnarrowing]
  311 |         case 0xFF534D42:  // CIFS_MAGIC_NUMBER
      |              ^~~~~~~~~~

With adding `u` for the `case`s, that does not make problem go away:

../src/wutil.cpp: In function 'int fd_check_is_remote(int)':
../src/wutil.cpp:311:14: error: narrowing conversion of '4283649346' from 'unsigned int' to 'int' [-Wnarrowing]
  311 |         case 0xFF534D42u: // CIFS_MAGIC_NUMBER
      |              ^~~~~~~~~~~

Only explicit cast in switch() to unsigned int helps to silence this warning.

Comment 1 Jonathan Wakely 2020-02-15 10:30:22 UTC
Not a compiler bug. The C++ standard requires this to be diagnosed.

That value cannot be converted to an int without changing its value. If you want the int value corresponding to that bit pattern, you need to use (int)0xFF534D42. If the switch is meant to be using unsigned, cast the switch expression to unsigned int (as suggested in the github issue).

Adding a u suffix makes no difference because the type is already unsigned int, because the value 0xFF534D42 is too large for int. The problem is that the switch expression is an int, so any case which can't be represented as an int is ill-formed.

Comment 2 Igor Raits 2020-02-15 10:32:45 UTC
(In reply to Jonathan Wakely from comment #1)
> Not a compiler bug. The C++ standard requires this to be diagnosed.
> 
> That value cannot be converted to an int without changing its value. If you
> want the int value corresponding to that bit pattern, you need to use
> (int)0xFF534D42. If the switch is meant to be using unsigned, cast the
> switch expression to unsigned int (as suggested in the github issue).
> 
> Adding a u suffix makes no difference because the type is already unsigned
> int, because the value 0xFF534D42 is too large for int. The problem is that
> the switch expression is an int, so any case which can't be represented as
> an int is ill-formed.

Hi Jonathan,

thanks for the reply!

So since the fix (casting the switch expression) is correct (I assume), I'll close this bug.


Note You need to log in before you can comment on or make changes to this bug.