llvm / llvm/llvm-project

[Clang] SourceRange on QualifiedTypeLoc doesn't include cv qualifiers

Open
#176,724 7 comments 0 reactions 0 assignees View on GitHub
clang:frontend
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Opening the following file
```cpp
const double* a;
```
in clang-query 21.1.8 and matching the typeLoc of the declaration
```
match varDecl(hasTypeLoc(typeLoc().bind("type")))
```
returns a source range that doesn't include the `const`, i.e. it makes the typeLoc unsuitable to use for clang-tidy Transformer checks:
```
Match #1:

/Users/tobi/test.cpp:1:1: note: "root" binds here
1 | const double* a;
| ^~~~~~~~~~~~~~~
/Users/tobi/test.cpp:1:7: note: "type" binds here
1 | const double* a;
| ^~~~~~~
1 match.
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with clang-query 21.1.8 using `const double* a;` and the shown `varDecl`/`typeLoc` matcher. Start by tracing how QualifiedTypeLoc computes its SourceRange in Clang's AST and Transformer-related source-range handling. Done means the matched typeLoc range includes the leading `const`, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.