Macro parameter is both stringified and pasted

ID

objectivec.maintainability.macro_stringify_paste_adjacent

Severity

low

Remediation Complexity

medium

Remediation Risk

medium

Remediation Effort

low

Resource

Preprocessor

Language

Objective-C

Description

Reports a macro replacement list in which a operator and a operator apply to the same parameter, as in #ab. A or a used on its own, and the GNU , VA_ARGS comma-swallowing idiom, are not reported.

Rationale

The standard does not fix the order in which and # are evaluated within one replacement list. Stringify-then-paste and paste-then-stringify produce different text, so the macro can expand to different code on different toolchains, or on different versions of the same one, with no diagnostic anywhere. Because the difference only shows up in the expanded output, it usually surfaces as a puzzling error at an unrelated call site.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Macro parameter is both stringified and pasted
#define XY_STR_CAT(a, b) #a##b

Remediation

Split the macro in two so each operator is applied in its own expansion and the order is forced - one macro that pastes, and a second that stringifies the result of the first. That also makes the intended order explicit to a reader.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved