[PATCH] D101387: remove single quotes around sugguestion diagnostic

Richard Trieu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 27 18:54:07 PDT 2021


rtrieu added a comment.

In D101387#2720500 <https://reviews.llvm.org/D101387#2720500>, @MaskRay wrote:

> @rtrieu Do we have a way appending arbitrary messages to a diagnostic template?

Not an arbitrary number.  The diagnostic format string is indexed, so it diagnostic string needs to know ahead of time how many arguments that will be passed to it.

The format types can be nested so you can do:

  "Some types: %select{|%1|%1 %2|%1 %2 %3|%1 %2 %3 and more}0"

Then you can pass {0,1,2,3} first, then follow with (0,1,2,3) strings.  And passing 4 first with 3 strings gets the "and more" attached to the end.  Otherwise, the string concatenation will need to be done before passing to the diagnostic.

For this case, I think to capture the variations used, we could use:

  "invalid value '%1' in '%0', %select{|for %3,}2 $plural{0:value must be %5|[1,4]:valid argument for '%0' are:%select{|%5|%5 %6|%5 %6 %7|%5 %6 %7 %8}4}4"

%0 - flag name
%1 - invalid value
%2 - if true, add extra "for %3"
%3 - string for extra "for", needed but ignored when %2 is false
%4 - count for valid arguments.  If 0, arbitrary string after "value must be"
%5-%8 - valid arguments

This supports up to 4 types and an arbitrary string.  Unifying the flang and clang diagnostics could simplify the string a bit more.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101387/new/

https://reviews.llvm.org/D101387



More information about the cfe-commits mailing list