Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang requires template keyword in places it should not (P0634, P1787) #95447

Open
zygoloid opened this issue Jun 13, 2024 · 6 comments
Open
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid

Comments

@zygoloid
Copy link
Collaborator

zygoloid commented Jun 13, 2024

Testcase:

template<typename T> void F() {
  // Clang requires `typename` and `template`. As discussed later in this
  // issue, should require only `typename`.
  T::X<int> f();
}

template<typename T> class C {
  // Should require neither; clang requires `template` but not `typename`.
  T::X<int> g();
};

template<typename T>
// Should require neither; clang requires `template` but not `typename`.
T::X<int> h();

Under P1787 (DR against C++20), per [temp.names]/3, the template keyword is not required before X in g and h, following the same rules that P0634 established for type-only contexts. But Clang (and GCC) seems to not implement this, and still requires template in g and h.

@zygoloid zygoloid added c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid labels Jun 13, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 13, 2024

@llvm/issue-subscribers-c-20

Author: Richard Smith (zygoloid)

Testcase: ```c++ template<typename T> void F() { T::X<int> f(); }

template<typename T> class C {
T::X<int> g();
};

template<typename T>
T::X<int> h();

Under P1787 (DR against C++20), per [temp.names]/3, the `template` keyword is not required before `X` in `g` and `h`, following the same rules that P0634 established for type-only contexts. But Clang (and GCC) seems to not implement this, and still requires `template` in `g` and `h`.
</details>

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 13, 2024

@llvm/issue-subscribers-clang-frontend

Author: Richard Smith (zygoloid)

Testcase: ```c++ template<typename T> void F() { T::X<int> f(); }

template<typename T> class C {
T::X<int> g();
};

template<typename T>
T::X<int> h();

Under P1787 (DR against C++20), per [temp.names]/3, the `template` keyword is not required before `X` in `g` and `h`, following the same rules that P0634 established for type-only contexts. But Clang (and GCC) seems to not implement this, and still requires `template` in `g` and `h`.
</details>

@zygoloid
Copy link
Collaborator Author

zygoloid commented Jun 13, 2024

Another case where Clang misses some of the P1787 changes for the handling of template:

template<template<typename> typename> struct X {};

template<typename T> void f() {
  X<T::R>(); // #1
  X<typename T::R>(); // #2
  X<T::template R>(); // #3
  X<typename T::template R>(); // #4
}

struct D { template<typename> class R {}; };
void g() { f<D>(); }

Under P1787:
#1 is valid, and is interpreted as naming the template D::R in the instantiation of f. (Prior to P1787 it was not valid. Clang incorrectly rejects.)
#2 is ill-formed; typename T::R unambiguously names a type, not a template. (Clang correctly rejects.)
#3 is valid but deprecated by P1787. (Prior to P1787, it was the only way to pass the member template as a template argument; Clang accepts without a deprecation warning.)
#4 is presumably ill-formed; T::R cannot be both a template and a type. (Clang rejects.)

Unlike the previous case (which should be applied only in the language modes with implicit typename / P0634), this one should presumably be applied retroactively across all C++ standards.

@shafik
Copy link
Collaborator

shafik commented Jun 13, 2024

CC @Endilll

@opensdh
Copy link

opensdh commented Jun 14, 2024

One more place is in typename T::template X<0>, as made optional by CWG1710, which is a DR presumably against all versions.

@shafik
Copy link
Collaborator

shafik commented Aug 19, 2024

Also see: #81731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid
Projects
Status: No status
Development

No branches or pull requests

4 participants