This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/50810] c++0x-compat does not warn about narrowing conversions
- From: "manu at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 22 Oct 2011 01:24:25 +0000
- Subject: [Bug c++/50810] c++0x-compat does not warn about narrowing conversions
- Auto-submitted: auto-generated
- References: <bug-50810-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50810
--- Comment #5 from Manuel LÃpez-IbÃÃez <manu at gcc dot gnu.org> 2011-10-22 01:24:25 UTC ---
(In reply to comment #4)
> (In reply to comment #3)
> > (detail: not sure about the 'if (!warn_narrowing) return;' at the beginning of
> > check_narrowing: probably we don't want -Wno-narrowing to suppress the warnings
> > enabled of -Wc++0x-compat)
>
> I think what you want is that -Wc++0x-compat enables -Wnarrowing independently
> of -std=, but still -Wc++0x-compat -Wno-narrowing should disable it. See the
> handling of Wlonglong in c-opts.c. So:
>
> if (!ok)
> {
> if (cxx_dialect != cxx98)
> pedwarn (input_location, OPT_Wnarrowing, "narrowing conversion of %qE "
> "from %qT to %qT inside { }", init, ftype, type);
> else
> warning_at (input_location, OPT_Wnarrowing, "narrowing conversion of
> %qE "
> "from %qT to %qT inside { }", init, ftype, type);
> }
>
You can even make this more compact by using emit_diagnostic:
emit_diagnostic ((cxx_dialect != cxx98) ? DK_PEDWARN : DK_WARNING,
input_location, OPT_Wnarrowing,
"narrowing conversion of %qE from %qT to %qT inside { }",
init, ftype, type);
The C FE has wrappers around something similar called pedwarn_c99, that is, a
pedwarn in C99, otherwise just a warning. You could add something similar to
C++.