Bug 1803333

Summary: Regression in -Wnarrowing on 32bit (GCC10)
Product: [Fedora] Fedora Reporter: Igor Raits <igor.raits>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: aoliva, avi.kivity, dmalcolm, fweimer, jakub, jwakely, law, mpolacek, msebor, nickc, sipoyare
Target Milestone: ---Keywords: Regression
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-02-15 10:32:45 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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.