llvm/llvm-project

[clang] warn on operator in macro expansion whose operand doesn't lie entirely within the same macro expansion

Open

#184,672 建立於 2026年3月4日

在 GitHub 查看
 (4 留言) (0 反應) (0 負責人)C++ (10,782 fork)batch import
clang:diagnosticsgood first issue

倉庫指標

Star
 (26,378 star)
PR 合併指標
 (平均合併 1天 2小時) (30 天內合併 1,000 個 PR)

描述

Testcase:

#define FOO 2+3
// 2+(3*4) == 14, not (2+3)*4 == 20
int n = FOO*4;

Clang doesn't warn on this, but I think it should. In general, I think a good heuristic would be: if the location of an operator is within a macro expansion, and an operand of that operator is not entirely within that same macro expansion, then warn. In this case, the + operator within FOO has an operand that extends to the 4 token, so we should warn.

This seems like something we could quickly and easily check for with our existing source location representation.

貢獻者指南