The check detects multi-statement macros that are used in unbraced conditionals.
Only the first statement will be part of the conditionals and the rest will fall
outside of it and executed unconditionally.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Nice check! I like the check, it would be very helpful. (I have struggled with this kind of bug before)
clang-tidy/misc/MultipleStatementMacroCheck.cpp | ||
---|---|---|
33 ↗ | (On Diff #52625) | I think you can put this anonymous namespace into the above one. |
37 ↗ | (On Diff #52625) | Should we check the result returned by Result.Context->getParents is valid or not? |
docs/clang-tidy/checks/misc-multiple-statement-macro.rst | ||
15 ↗ | (On Diff #52625) | Would be better to add a comment to explain the sample. |
Minor fixes
docs/clang-tidy/checks/misc-multiple-statement-macro.rst | ||
---|---|---|
15 ↗ | (On Diff #52625) | The sentence just before the example explains what the problem is. |
LG with a nit.
clang-tidy/misc/MultipleStatementMacroCheck.cpp | ||
---|---|---|
99 ↗ | (On Diff #52702) | If I saw this message from a tool, I wouldn't get what it means right away. Can you come up with an easier to read alternative? I can only suggest multiple statement macro used without braces, but maybe a more self-documenting message comes to your mind. |
docs/clang-tidy/checks/misc-multiple-statement-macro.rst | ||
16 ↗ | (On Diff #52702) | While I see your point, this doesn't seem worse to me: if (do_increment) INCREMENT_TWO(a, b); // `(b)++;` will always be executed. Up to you though. |
Change warning message.
clang-tidy/misc/MultipleStatementMacroCheck.cpp | ||
---|---|---|
99 ↗ | (On Diff #52702) | Sure. |
clang-tidy/misc/MultipleStatementMacroCheck.cpp | ||
---|---|---|
100 ↗ | (On Diff #53398) | Now it seems clear to me. Thanks! |