On 02/09/16 18:44, David Malcolm wrote:
Much better would be to have the formatting be done inside the
diagnostics subsystem's call into pp_format, with something like this:

  warning_at_rich_loc_n (&richloc, OPT_Wrestrict,
                         arg_positions
.length (),
                         "passing argument %i to restrict
-qualified"
                         " parameter aliases with argument
%FIXME",
                         "passing argument %i to restrict
-qualified"
                         " parameter aliases with arguments
%FIXME",
                         param_pos + 1,

 &arg_positions);

Yes, building up diagnostic messages from pieces is discouraged: https://gcc.gnu.org/codingconventions.html#Diagnostics

and have %FIXME (or somesuch) consume &arg_positions in the va_arg,
printing the argument numbers there.  Doing it this way also avoids
building the string for the case where Wrestrict is disabled, since the
pp_format only happens after we know we're going to print the warning.

Is it possible to pass template arguments through ... ? And how does va_arg know the type of the particular template passed?

Assuming that there isn't yet a pre-canned way to print a set of
argument numbers that I've missed, the place to add the %FIXME-handling
would presumably be in default_tree_printer in tree-diagnostic.c -
though it's obviously nothing to do with trees. (Or if this is too
single-purpose, perhaps there's a need to temporarily inject one-time
callbacks for consuming custom args??).

I'm surprised we don't have a function pp_vec to print/debug a vec<>, but perhaps it is simpler to convert arg_pos to a 'char *' and use %s instead of %FIXME or call-backs.

Cheers,

        Manuel.

Reply via email to