This is a utility function for adding a statement to be executed after a specified one using FixItHints. It is designed to provide good formatting and protection against lack of curly brackets (for example when your preceding statement is in a for loop). This is a prerequisite to D133956 - one of the new CUDA checks. It also relies on D133725 to be able to search for comments right after a certain token.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
There's some merit in this, like wrapping the previous statement in braces.. However, clang-tidy should not focus on the formatting aspect as we have clang-format built in to address formatting decisions, and any special formatting you do in here would likely be undone by the users configuration.
It would also be nice to add in some unittests to demonstrate that braces are currently inserted etc.
How does this handle pathological cases like the statement being the iteration-expression of a for loop, or a init-statement in an if/switch/range-for loop. The documentation looks like it tries to explain that, but it doesn't do a great job IMHO.
It doesn't really, it's mostly meant for cases where we know that the statement will be in the body and it's only added in the utils because it's needed for D133956, but I can just move it to inside the check if you believe that it won't be as useful for the general case. The reason I want to preserve the statement to which the comments relate to is because if I put the new statement/macro invocation right after the current statement then the formatted will move the comments to the new line with the new statement instead of keeping them in the same line as the current statement (and in case of macros I'm not sure if it will even move it to the next line at all)