Re: GDB 8.1 build error

Pedro Alves <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.