Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Paul Koning <paulkoning@comcast.net>, gdb@sourceware.org
Subject: Re: GDB 8.1 build error
Date: Wed, 02 May 2018 09:42:00 -0000	[thread overview]
Message-ID: <a28595b3-ed78-2a6b-36c9-48965efa87f9@redhat.com> (raw)
In-Reply-To: <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


  reply	other threads:[~2018-05-02  9:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-27 18:02 Paul Koning
2018-04-27 18:38 ` Simon Marchi
2018-04-27 18:57   ` Paul Koning
2018-04-27 19:01     ` Paul Koning
2018-04-27 19:08     ` Simon Marchi
2018-04-27 19:18       ` Paul Koning
2018-04-27 20:41       ` Paul Koning
2018-04-27 19:10     ` Simon Marchi
2018-04-27 19:10     ` Pedro Alves
2018-04-27 19:39       ` Simon Marchi
2018-04-27 20:00         ` Pedro Alves
2018-04-27 20:16         ` Pedro Alves
2018-04-27 20:24           ` Simon Marchi
2018-04-27 20:41             ` Pedro Alves
2018-04-27 20:48               ` Simon Marchi
2018-05-02  9:42                 ` Pedro Alves [this message]
2018-05-02 10:13                   ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a28595b3-ed78-2a6b-36c9-48965efa87f9@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=paulkoning@comcast.net \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox