llvm / llvm/llvm-project

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

Open
#184,672 4 comments 0 reactions 0 assignees View on GitHub
clang:diagnostics good first issue
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Testcase:
```c++
#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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.