Bug 1304835 - GCC 6 bogus narrowing conversion warning
Summary: GCC 6 bogus narrowing conversion warning
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: 2016-02-04 18:21 UTC by Andy Lutomirski
Modified: 2016-02-04 20:00 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-02-04 20:00:04 UTC
Type: Bug


Attachments (Terms of Use)

Description Andy Lutomirski 2016-02-04 18:21:42 UTC
fish is failing to build from source on rawhide because:

g++ -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -march=armv7-a -mfpu=vfpv3-d16  -mfloat-abi=hard -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -fno-exceptions -Wall -Wno-sign-compare -D_GNU_SOURCE=1 -D_ISO99_SOURCE=1  -DLOCALEDIR=\"/usr/share/locale\" -DPREFIX=L\"/usr\" -DDATADIR=L\"/usr/share\" -DSYSCONFDIR=L\"/etc\" -DBINDIR=L\"/usr/bin\" -DDOCDIR=L\"/usr/share/doc/fish\"   -DFISH_BUILD_VERSION=\"2.2.0\"  -c -o fish_tests.o fish_tests.cpp
fish_tests.cpp: In function 'void test_utf8()':
fish_tests.cpp:1148:57: error: narrowing conversion of '-2' from 'int' to 'wchar_t' inside { } [-Wnarrowing]
     wchar_t wb[] = {-2, 0xa, (wchar_t)0xffffffff, 0x0441};
                                                         ^
This seems bogus to me.

First, it only warns at all on arm.  That's odd.

Second, if I build this on Fedora 23:

#include <stddef.h>

unsigned short wb[] = {-2, 0xa, (unsigned short)0xffffffff, 0x0441};
unsigned short bad[] = {-2, 0xa, 0xffffffff, 0x0441};

I get:

narrowing.c:5:34: warning: large integer implicitly truncated to unsigned type [-Woverflow]
 unsigned short bad[] = {-2, 0xa, 0xffffffff, 0x0441};

GCC 5.3.1 has it right: the implicit conversion is bad, but I think the explicit conversion should be fine.

Comment 1 Marek Polacek 2016-02-04 18:24:42 UTC
As explained at https://gcc.gnu.org/gcc-6/porting_to.html the default -std option is different in GCC 6.  This code fails with GCC 5 as well if you use -std=c++11, so it's a C++98 vs C++11 difference, not a GCC 5 vs GCC 6 difference.

Comment 2 Jonathan Wakely 2016-02-04 18:44:29 UTC
(In reply to Andy Lutomirski from comment #0)
> fish_tests.cpp:1148:57: error: narrowing conversion of '-2' from 'int' to
> 'wchar_t' inside { } [-Wnarrowing]
>      wchar_t wb[] = {-2, 0xa, (wchar_t)0xffffffff, 0x0441};
>                                                          ^
> This seems bogus to me.
> 
> First, it only warns at all on arm.  That's odd.

Signed vs unsigned wchar_t I assume.

> Second, if I build this on Fedora 23:
> 
> #include <stddef.h>
> 
> unsigned short wb[] = {-2, 0xa, (unsigned short)0xffffffff, 0x0441};
> unsigned short bad[] = {-2, 0xa, 0xffffffff, 0x0441};
> 
> I get:
> 
> narrowing.c:5:34: warning: large integer implicitly truncated to unsigned
> type [-Woverflow]
>  unsigned short bad[] = {-2, 0xa, 0xffffffff, 0x0441};
> 
> GCC 5.3.1 has it right: the implicit conversion is bad, but I think the
> explicit conversion should be fine.

It's not complaining about the explicit conversion, it's complaining about the -2, which the C++11 standard says is ill-formed.

Comment 3 Andy Lutomirski 2016-02-04 20:00:04 UTC
Oh, right.  That makes considerably more sense.  That'll teach me to read errors more carefully.


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