[Bug c++/69864] Fix various Wnarrowing minor issues

manu at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Feb 19 11:37:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69864

--- Comment #10 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
(In reply to Markus Trippelsdorf from comment #9)
> > * Create a new function in diagnostic.c, e.g., 
> > 
> > extern diagnostic_t pederror (location_t, int, const char *, ...)
> >      ATTRIBUTE_GCC_DIAG(3,4);
> > 
> > and replace the kludge in cp/typeck2.c with it (possibly fixing PR69872
> > along the way). Document when some warnings might be errors (like we have
> > precise definitions for permerror/pedwarn).
> 
> The kludges are there because gcc used to emit an error even with
> -Wno-narrowing.
> That broke tons of existing C++ code. There is such a thing as QOI and that
> means you have to use a compromise sometimes.

This is the kludge I'm talking about:

        {
          int savederrorcount = errorcount;
          global_dc->pedantic_errors = 1;
          pedwarn (loc, OPT_Wnarrowing,
                   "narrowing conversion of %qE from %qT to %qT "
                   "inside { }", init, ftype, type);
          if (errorcount == savederrorcount)
            ok = true;
          global_dc->pedantic_errors = flag_pedantic_errors;
        }

I'm just suggesting to created a pederror function to hide this uglyness and
make such "diagnostics mandated by the standard for which we give an error but
allow the user to downgrade to a warning" a properly defined and consistently
behaved function before it extends by copy-pasting.


More information about the Gcc-bugs mailing list