llvm / llvm/llvm-project

[clang][frontend] Clang doesn't recognize certain `template-id`s as referring to the current instantiation

Open
#172,243 3 comments 0 reactions 0 assignees View on GitHub
c++ clang:frontend confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

(Disclaimer: not a language lawyer)

Consider this class ([godbolt](https://godbolt.org/z/o6zEbda3j)):
```cpp
template
struct S {
static constexpr int n = i;
using U = S;
S(const U&) = default;
S(U&&) = default;
U& operator=(const U& u) = default;
U& operator=(U&& u) = default;
~S() = default;

using foo = int;
S::foo no_warning;
S::foo warning;
};
```
In my understanding, inside the class, `U` refers to the current instantiation according to the equivalence rules in [[temp.dep.type]/2](https://eel.is/c++draft/temp.dep#type-2). Clang doesn't seem to implement those rules. That causes it to do things like:
- Emit a warning `missing 'typename' prior to dependent type name` on the declaration of `warning`.
- Not recognize `S(U&&) = default;` as a move constructor (i.e. calling `isMoveConstructor` on that `CXXConstructorDecl` returns false). This leads to [false positives in certain clang-tidy checks](https://github.com/llvm/llvm-project/issues/116055).

Contributor guide

Open the contributing guide

Research direction

Start with the Godbolt reproducer in the issue and trace Clang's handling of dependent names and current-instantiation template-ids in the frontend. Check how the CXXConstructorDecl isMoveConstructor result is determined for S. Done means S::foo no longer needs the warning and the defaulted constructor is recognized as a move constructor, avoiding the reported clang-tidy false positives.

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.