llvm / llvm/llvm-project

clang-scan-deps fails to parse C++ files when comparing a macro against a numeric literal that contains digit separators in preprocessor.

Open
#177,170 4 comments 0 reactions 0 assignees View on GitHub
clang-tools-extra
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

clang version 21.1.8
Target: x86_64-w64-windows-gnu
Thread model: posix

```cpp
#if __cplusplus >= 2020'00L
#endif

int main(int argc, char *argv[])
{
return 0;
}
```
clang-scan-deps fails with such error
`test.cpp:1:24: error: token is not a valid binary operator in a preprocessor subexpression`

Accroding to CMake policy [CMP0155](https://cmake.org/cmake/help/latest/policy/CMP0155.html)
> CMake 3.27 and below assume that C++ sources do not import modules. CMake 3.28 and above prefer to assume that C++ sources in targets using C++20 or higher might import modules, and must be scanned before compiling, unless explicitly disabled.

clang-scan-deps is always invoked with CMake 3.28+ and C++20 or higher, even if I am not utilizing C++ module features. (I encounter the bug in NIVADIA/stdexec library where there are many feature testing macros used with numeric literals which contain digit separators.)

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the test.cpp example using clang-scan-deps, then trace how its preprocessor evaluates the #if comparison containing a digit separator. Compare this path with ordinary C++ preprocessing, and add coverage so the sample parses successfully without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.