[cfe-dev] Source range error

Paul Curtis plc at rowley.co.uk
Thu Dec 2 05:57:09 PST 2010


Hi,

Clang currently produces quite a wide source range for this particular
format error:

> clang -fsyntax-only foo1.c
foo1.c(5) :  warning: invalid conversion specifier '!' [-Wformat]
  printf("Format %d, is %! %f", 1, 2, 4.4);
                   ~~~~~~^
1 warning generated.

The source range spans from the end of the last formatter to the end of the
current one.  

In ParsePrintfSpecifier you have:

  if (k == ConversionSpecifier::InvalidSpecifier) {
    // Assume the conversion takes one argument.
    return !H.HandleInvalidPrintfConversionSpecifier(FS, Beg, I - Beg);
  }

...whereas I think what you mean is:

  if (k == ConversionSpecifier::InvalidSpecifier) {
    // Assume the conversion takes one argument.
    return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, I - Start);
  }

With this patch (sorry, it's so small I just can't bring myself to attach
one) you now get:

> clang -fsyntax-only -Wall foo1.c
foo1.c(5) :  warning: invalid conversion specifier '!' [-Wformat]
  printf("Format %d, is %! %f", 1, 2, 4.4);
                        ~^
1 warning generated.

This is more appropriate, IMO.  It certainly is when expanding source ranges
in an IDE.

Regards,

--
Paul Curtis, Rowley Associates Ltd   http://www.rowley.co.uk
SolderCore arriving Winter 2010!   http://www.soldercore.com







More information about the cfe-dev mailing list