How to disable narrowing conversion warnings?
Asked Answered
P

3

22

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.

Professional answered 30/11, 2013 at 16:24 Comment(7)
You mean you even get them if you write explicit typecasts?Zuzana
@MrLister, no, I need a quick "fix".Professional
Oh, so no rewriting of code? Then I misunderstood, sorry.Zuzana
oh. it feels like it is easier to fix them....Professional
“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 gcc.gnu.org/onlinedocs/gcc/Warning-Options.html: Well I can find an instance of “-Wnarrowing”. Did you try -Wno-narrowing?Katleen
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.Huffish
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). (gcc.gnu.org/bugzilla/show_bug.cgi?id=55783). There's no way around it without modifying the code.Demetria
C
34

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

Commendatory answered 31/12, 2014 at 18:36 Comment(1)
It worked!! Was stuck trying to install CTCdecoder on the new MacBook M1 for 2 days!!Mucronate
M
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)

Magnetron answered 1/4, 2020 at 20:40 Comment(0)
N
1

try this option -Wno-error=narrowing

Nevil answered 16/11, 2023 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.