[cfe-dev] Help writing fixits in clang

Nicolas Lesser via cfe-dev cfe-dev at lists.llvm.org
Wed Dec 12 03:13:23 PST 2018


Hi!

A bit of an off-topic note beforehand: Why not add a space inside of parens?

Fixits are actually pretty straightforward to implement. It's like this:

Diag(ErrorLoc, diag::err_missing_foo) << VarName // some diagnostic,
unchanged
<< FixItHint::CreateInsertion(ErrorLoc, " foo");

This creates a diagnostic with a fixit at ErrorLoc and inserts foo there.
There are other fixit hints that you can use like replacement.

Hope that helps!

On Wed, Dec 12, 2018, 11:03 AM Andy Gibbs via cfe-dev <
cfe-dev at lists.llvm.org wrote:

> Hi,
>
> I'd like to add a fixit (or two) to suggest parentheses in the following
> expressions:
>
>   struct S { float value; };
>   S operator"" _f(long double t);
>
>   void test() {
>     int i = 0x2e+'a';          // fixit: (0x2e)+'a'
>     float j = 100.0_e-10.0;    // fixit: (100.0_e)-10.0
>     float k = 100.0_f.value;   // fixit: (100.0_f).value
>     int l = 0x2e+i;            // fixit: (0x2e)+i
>   }
>
> However, I am not sure of the correct way to do this.
>
> Would someone, please, give me a quick tutorial or, if easier, point out
> an similar example in the clang code.
>
> Many thanks,
> Andy
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181212/7e236ec0/attachment.html>


More information about the cfe-dev mailing list