20

I use -Wall and updating to new gcc I have got a lot of warning: narrowing conversion. I want to disable them, but leave all other warnings untouched (ideally).

I can find nothing about narrowing in http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html

How to disable narrowing conversion warnings? Is it possible at all?

P.S.

  1. I need to Disable warnings, not fix them in the source code.

  2. Blind -Wno-conversion doesn't help.

klm123
  • 12,105
  • 14
  • 57
  • 95
  • You mean you even get them if you write explicit typecasts? – Mr Lister Nov 30 '13 at 16:35
  • @MrLister, no, I need a quick "fix". – klm123 Nov 30 '13 at 16:36
  • 1
    Oh, so no rewriting of code? Then I misunderstood, sorry. – Mr Lister Nov 30 '13 at 16:38
  • oh. it feels like it is easier to fix them.... – klm123 Nov 30 '13 at 17:03
  • 4
    _“I have got a lot of `warning: narrowing conversion`”_: Ok, for what code? Is that the exact complete warning message? _“I can find nothing about `narrowing` in http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html”_: Well I can find an instance of “`-Wnarrowing`”. Did you try `-Wno-narrowing`? – gx_ Nov 30 '13 at 17:06
  • The newer versions of gcc tend to write the warning option used to enable the warning as part of the warning. You just need to inject a `no-` at the obvious place. I think it is `-Wno-narrowing`. – Dietmar Kühl Nov 30 '13 at 18:14
  • Ran into the same issue in gcc4.4.7. It turns out the -Wno-narrowing flag has been broken for a while because it's gone back and forth on whether the condition should trigger a warning (prior to and after 4.6) or an error (4.6). (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55783). There's no way around it without modifying the code. – mtalexan Nov 15 '16 at 23:05

2 Answers2

31

As gx_ said, adding -Wno-narrowing to your command line should ignore those errors. Encountered this myself when upgrading to C++0x.

Murphy
  • 3,827
  • 4
  • 21
  • 35
Stryck
  • 695
  • 1
  • 6
  • 11
4

As a small FYI, as detailed on https://clang.llvm.org/docs/DiagnosticsReference.html#wnarrowing this is an alias for -Wno-c++11-narrowing (there are multiple narrowing warning flags)

Ben
  • 560
  • 4
  • 6