llvm / llvm/llvm-project

Clang fails to merge default template arguments across multiple declarations of a member class template within a class template

Open
#160,982 6 comments 0 reactions 0 assignees View on GitHub
clang:frontend diverges-from:edg diverges-from:gcc diverges-from:msvc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Similar to #135442, but for class templates.

Clang rejects this code, while MSVC, GCC, and EDG accept it ([godbolt](https://godbolt.org/z/44fr4814G)):
```cpp
template
struct Foo {
template
struct Bar;

template
struct Bar {};

using MyBar = Bar<>;
};

template struct Foo;
```
According to [[temp.param]/18](https://eel.is/c++draft/temp.param#18), the default arguments for `Bar` should be merged, so this code should be valid.

Notably, the issue disappears if:
- the enclosing class is non-template, or
- the default argument is placed on the definition rather than the declaration ([godbolt](https://godbolt.org/z/z5nbdWTso)).

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.