llvm / llvm/llvm-project

error: template template argument ... is more constrained than template template parameter ... when it's actually not

Open
#162,023 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend concepts
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Given the following program:
```cpp
#include

template
concept some_concept = !std::is_same_v;

template
struct A1 {};

template
struct A2 {};

template typename T>
struct X {
template typename T_>
using change_t = X;
};

int main() {
auto x1 = X{};
auto x2 = typename decltype(x1)::template change_t{};
}
```
it gives the following error:
```
:19:17: error: template template argument 'A1' is more constrained than template template parameter 'T'
19 | auto x1 = X{};
| ^~
:12:44: note: 'T' declared here
12 | template typename T>
| ^
:7:8: note: 'A1' declared here
7 | struct A1 {};
| ^
```
It fails when trying to instantiate the template `X`. If we strip away some seemingly unrelated code however, it compiles just fine:
```cpp
#include

template
concept some_concept = !std::is_same_v;

template
struct A1 {};

template typename T>
struct X {

};

int main() {
auto x1 = X{};
}
```
Tested on clang trunk

Contributor guide

Open the contributing guide

Research direction

Start by reproducing both the full and reduced programs on clang trunk, then compare the template-template argument constraint diagnostics during X instantiation. Trace the interaction introduced by change_t and verify that the full program accepts A1 while retaining the intended constraint checks for template arguments.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.