Issue 61416
Summary [clang-tidy] add_new_check.py creates a faulty FixItHint
Labels new issue
Assignees
Reporter RedPenguin100
    When the `add_new_check.py` script is invoked to create a new vanilla custom clang-tidy check, the following code is emitted inside the check override function:

```cpp
 diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
      << MatchedDecl;
  diag(MatchedDecl->getLocation(), "insert 'awesome'", DiagnosticIDs::Note)
      << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
```

Running clang tidy with `--fix` won't fix the function name.
Changing the code to the following will work:

```cpp
  diag(MatchedDecl->getLocation(), "function %0 is insufficiently awesome")
      << MatchedDecl
      << FixItHint::CreateInsertion(MatchedDecl->getLocation(), "awesome_");
 diag(MatchedDecl->getLocation(), "insert 'awesome'", DiagnosticIDs::Note);
```

I'm not sure why but I think the reason for this is that the FixItHint comes after a `DiagnosticsIDs::Note` which possibly prevents fixes afterwards. Also removing the last line altogether might work, but I'm not sure how the mainteners want this to look like.

I hope I didn't break too many rules, this is my first time posting, was trying to understand why this isn't working for way too long 

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to