A macro expands to several statements that are not wrapped into one

tx0/c:macro-statements-unwrappedstrictwarningreliability/logicdepth fastbug

What it finds

#define SWAP(a, b) t = a; a = b; b = t: a macro made of several statements is not one statement where it is used, so in if (x > y) SWAP(x, y); only the first statement depends on the condition. Wrapping the body in do { ... } while (0) makes it one.

The body of a macro with parameters must hold a semicolon outside parentheses and braces with more tokens after it, and not start with a keyword that makes it one statement, as do, if, a loop or a brace does. Bodies that start like declarations, which are meant for the top level, are left alone.

From the rule's source, macro_statements_unwrapped.rs.

Example from the rule's tests
#define SWAP(a, b) t = a; a = b; b = ttx0 reports: SWAP expands to several statements#define SWAP2(a, b) do { t = a; a = b; b = t; } while (0)#define LOOP(i, n) for (i = 0; i < n; i++)#define FIELDS(t) int t##_a; int t##_b;int t;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:macro-statements-unwrapped" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/c:macro-statements-unwrapped] reason="..."

tx0 explain tx0/c:macro-statements-unwrapped shows the same in the terminal. Found a false positive? Report it.