This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: GDB 8.1 build error
- From: Pedro Alves <palves at redhat dot com>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>
- Cc: Paul Koning <paulkoning at comcast dot net>, gdb at sourceware dot org
- Date: Wed, 2 May 2018 10:41:49 +0100
- Subject: Re: GDB 8.1 build error
- References: <214C80CC-1173-41F6-AAA1-39C9D39E28B2@comcast.net> <454707570722fc0220074c0eca015a8f@polymtl.ca> <D029885B-D093-4416-9957-371E3D08495E@comcast.net> <c744d369-801b-c29f-dd3d-961c57ebec74@redhat.com> <e687057d79e17944e9a77912fd22bac0@polymtl.ca> <6171a043-e486-85ec-bdbb-2077a2b5ebd0@redhat.com> <b02d45ab46b5a572724bccbbb5eed7d4@polymtl.ca> <9ed9617b-987e-3225-8518-a43eda0b5548@redhat.com> <13bcba4a8a70bcd977a7e644dd59e4bf@polymtl.ca>
On 04/27/2018 09:41 PM, Simon Marchi wrote:
> On 2018-04-27 16:24, Pedro Alves wrote:
>> -Wnarrowing is on by default on gcc, and -w disables it.
>
> But it's a warning by default, not an error (like clang). I think that's the important distinction.
OK, That suggests to me that clang has -Werror=narrowing enabled by
default, instead of -Wnarrowing.
But I still think that the real issue is that gcc and clang
behave differently wrt "-w" precedence.
Note, with:
$ cat narrow.cc
int return_int () { return 42; }
char buf[2] = { return_int () };
#1 - even if you make gcc error out with -Werror=narrowing, a subsequent "-w"
cancels the error/warning, not so with clang:
$ g++ -std=gnu++17 narrow.cc -c -Werror=narrowing -w
$ clang++ -std=gnu++17 narrow.cc -c -Werror=narrowing -w
narrow.cc:2:17: error: non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list [-Wc++11-narrowing]
#2 - If you put "-Wno-error=narrowing", after the "-w", then both compilers
suppress the warning/error:
$ clang++ -std=gnu++17 narrow.cc -c -Werror=narrowing -w -Wno-error=narrowing
$ g++ -std=gnu++17 narrow.cc -c -Werror=narrowing -w -Wno-error=narrowing
#3 - For completeness, adding "-Werror=narrowing" after the -w, shows #1 again:
$ g++ -std=gnu++17 narrow.cc -c -w -Werror=narrowing
$ clang++ -std=gnu++17 narrow.cc -c -w -Werror=narrowing
narrow.cc:2:17: error: non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list [-Wc++11-narrowing]
$ g++ -std=gnu++17 narrow.cc -c -Werror=narrowing -w -Werror=narrowing
$ clang++ -std=gnu++17 narrow.cc -c -Werror=narrowing -w -Werror=narrowing
narrow.cc:2:17: error: non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list [-Wc++11-narrowing]
So it seems to be the issue here is more about "-w" precedence over all
warning switches than about what is enabled by default.
To confirm this, we can see the same thing with any other warning:
~~~~~~~~~~~~
$ gcc unused.c -c -Werror=unused-variable
unused.c: In function ‘function’:
unused.c:1:23: error: unused variable ‘i’ [-Werror=unused-variable]
int function () { int i; return 42; }
^
cc1: some warnings being treated as errors
~~~~~~~~~~~~
~~~~~~~~~~~~
$ clang unused.c -c -Werror=unused-variable
unused.c:1:23: error: unused variable 'i' [-Werror,-Wunused-variable]
int function () { int i; return 42; }
^
1 error generated.
~~~~~~~~~~~~
vs
$ gcc unused.c -c -Werror=unused-variable -w
$ clang unused.c -c -Werror=unused-variable -w
unused.c:1:23: error: unused variable 'i' [-Werror,-Wunused-variable]
So seems like we could handle this my making --disable-build-warnings
use "-Wno-error -w" instead of just "-w". But I'd suggest checking with
clang and/or gcc folks to confirm the difference is intentional too.
Thanks,
Pedro Alves