[PATCH] PR driver/69265: add hint for options with misspelled arguments

Manuel López-Ibáñez lopezibanez@gmail.com
Tue May 10 23:56:00 GMT 2016


On 10/05/16 22:03, David Malcolm wrote:
> On Tue, 2016-05-10@22:09 +0200, Bernhard Reutner-Fischer wrote:
>> On Mon, May 09, 2016@08:14:47PM -0400, David Malcolm wrote:
>>
>>> -      inform (loc, "valid arguments to %qs are: %s", option
>>> ->opt_text, s);
>>> +      const char *hint = find_closest_string (arg, &candidates);
>>> +      if (hint)
>>> +	inform (loc, "valid arguments to %qs are: %s; did you mean
>>> %qs?",
>>> +		option->opt_text, s, hint);
>>> +      else
>>> +	inform (loc, "valid arguments to %qs are: %s", option
>>> ->opt_text, s);
>>> +
>>
>> btw.. did you consider a format specifier for this ";did you mean
>> %qs"
>> common stanza?
>>
>> inform (loc, "valid arguments to %qs are: %s%qhs", x, y, hint);
>> (let's say) where the specifier would end up empty if hint was NULL.
>
> It would save a conditional, but it seems a bit too much like "magic"
> to me; I prefer the explicitness of the existing approach.

Also, I'm pretty sure that %qX will print `; did you mean hint?', that is, with 
the quotes all messed up. GCC has the same issue when printing typedefs (aka). 
GCC prints:

error: member reference base type 'pid_t {aka int}' is not a structure or union

instead of the more correct quoting used by Clang:

error: member reference base type 'pid_t' (aka 'int') is not a structure or union

But perhaps a wrapper or a dedicated overload can hide some of the details 
within diagnostic.c without requiring a new format specifier:

inform_with_hint (const char *target, const auto_vec<const char *> *candidates,
                   location_t, const char *gmsgid, ...)

Eventually, we should move to an API like the rich_location one, where 
diagnostics can be explicitly constructed, properties can be dynamically added 
and then the diagnostic is explicitly emitted.

Perhaps even an API that uses the Named Parameter Idiom?

diagnostic.at(rich_loc)
	  .with_hint(target, candidates)
	  .inform("something").print()

Cheers,
	Manuel.



More information about the Gcc-patches mailing list