[cfe-dev] Highlighting bad encodings?

Eli Friedman eli.friedman at gmail.com
Sun Oct 28 02:21:57 PDT 2012


On Sun, Oct 28, 2012 at 12:13 AM, Seth Cantrell <seth.cantrell at gmail.com> wrote:
> While fixing a small issue with range highlighting of invalid character encodings in string literals I wondered about the desirability if highlighting _every_ invalid character encoding in a string literal rather than simply the first one. Is there any reason to prefer only highlighting the first one?
>
> The result would be something like this:
>
> wrong-encoding.c:28:6: warning: illegal character encoding in string literal [-Winvalid-source-encoding]
>   "xx<E9><BF><E9><BF>d";
>      ^~~~~~~~
> wrong-encoding.c:28:8: warning: illegal character encoding in string literal [-Winvalid-source-encoding]
>   "xx<E9><BF><E9><BF>d";
>              ^~~~~~~~
>
> Attached is a patch that highlights all the invalid characters, but if possible I'd like them all to be highlighted in a single diagnostic. Is it possible to apply multiple ranges to one diagnostic in this case?

There isn't any limit to the number of ranges.  I don't think there's
any existing code which tries to add ranges to highlight in a loop...
but it should be possible.  You just need to bind a reference to the
DiagnosticBuilder to keep it alive long enough.

-Eli




More information about the cfe-dev mailing list