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
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 | ||
---|---|---|
34 | I think you can put this anonymous namespace into the above one. | |
38 | Should we check the result returned by Result.Context->getParents is valid or not? | |
docs/clang-tidy/checks/misc-multiple-statement-macro.rst | ||
16 | Would be better to add a comment to explain the sample. |
Minor fixes
docs/clang-tidy/checks/misc-multiple-statement-macro.rst | ||
---|---|---|
16 | The sentence just before the example explains what the problem is. |
LG with a nit.
clang-tidy/misc/MultipleStatementMacroCheck.cpp | ||
---|---|---|
99 | 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 | 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 | Sure. |
clang-tidy/misc/MultipleStatementMacroCheck.cpp | ||
---|---|---|
101 | Now it seems clear to me. Thanks! |
I feel it nicer if you merge this namespace with the one at line 20.