public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/50810] c++0x-compat does not warn about narrowing conversions
Date: Sat, 22 Oct 2011 01:25:00 -0000	[thread overview]
Message-ID: <bug-50810-4-8ebWxd2NRp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <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++.


  parent reply	other threads:[~2011-10-22  1:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-20 13:41 [Bug c++/50810] New: " public at alisdairm dot net
2011-10-20 13:55 ` [Bug c++/50810] " redi at gcc dot gnu.org
2011-10-21 22:50 ` paolo.carlini at oracle dot com
2011-10-21 22:57 ` paolo.carlini at oracle dot com
2011-10-22  1:15 ` manu at gcc dot gnu.org
2011-10-22  1:25 ` manu at gcc dot gnu.org [this message]
2011-10-22  4:38 ` jason at gcc dot gnu.org
2011-10-22  9:19 ` paolo.carlini at oracle dot com
2011-10-23  0:37 ` paolo.carlini at oracle dot com
2011-10-23  2:08 ` jason at redhat dot com
2011-10-23  2:13 ` paolo.carlini at oracle dot com
2011-10-23 18:37 ` paolo at gcc dot gnu.org
2011-10-23 18:37 ` paolo.carlini at oracle dot com
2011-10-23 21:02 ` paolo at gcc dot gnu.org
2011-10-23 21:03 ` paolo.carlini at oracle dot com
2011-10-23 21:16 ` paolo at gcc dot gnu.org
2011-10-23 21:44 ` manu at gcc dot gnu.org
2011-10-23 21:56 ` manu at gcc dot gnu.org
2011-10-24 12:36 ` manu at gcc dot gnu.org
2011-11-02 20:17 ` jason at gcc dot gnu.org
2011-11-02 20:54 ` jason at gcc dot gnu.org

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=bug-50810-4-8ebWxd2NRp@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).