-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Class template partial specialization with concept-auto non-type parameter is not supported #77377
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
Comments
@llvm/issue-subscribers-clang-frontend Author: None (Fedr)
In this program
```
#include <concepts>
template <auto> template <std::same_as<int> auto p> A<0> a;
error: class template partial specialization is not more specialized than the primary template [-Winvalid-partial-specialization]
|
Interestingly, it does work with a requires clause |
We have to compare the template parameter equivalence before going through the constraint check, per [temp.func.order]p6.2.2:
And the definition for 'equivalent' is at [temp.over.link]p6.3:
And this is implemented by bc62fb9.
I think this could also explain why using a requires expression does work -- the parameters are considered equivalent that way. (I'm not 100% sure the standard is intended to reject such cases. CC @zygoloid for some opinions.) |
In this case, the template parameters are equivalent, so we should continue to [temp.func.order]/6.4 which orders the function templates based on their constraints. |
…92425) When the argument passed to `ASTContext::getUnconstrainedType` is an unconstrained `AutoType`, will return the argument unchanged. However, when called with a constrained `AutoType`, an unconstrained, non-dependent `AutoType` will be returned even if the argument was dependent. Consider the following: ``` template<typename T> concept C = sizeof(T) == sizeof(int); template<auto N> struct A; template<C auto N> struct A<N>; // error: class template partial specialization is not more specialized than the primary template ``` When comparing the template parameters for equivalence, `ASTContext::getUnconstrainedType` is used to remove the constraints per [temp.over.link] p6 sentence 2. For the template parameter `N` of the class template, it returns a dependent `AutoType`. For the template parameter `N` of the class template partial specialization, it returns a non-dependent `AutoType`. We subsequently compare the adjusted types and find they are not equivalent, thus we consider the partial specialization to not be more specialized than the primary template per [temp.func.order] p6.2.2. This patch changes `ASTContext::getUnconstrainedType` such that the dependence of a constrained `AutoType` will propagate to the returned unconstrained `AutoType`. This causes the above example to be correctly accepted, fixing #77377.
Closed by #92425 |
In this program
A<auto>
is a class template with non-type parameter, andA<std::same_as<int> auto>
is its specialization forint
parameters. The program is accepted by GCC and MSVC, but Clang complains:Online demo: https://godbolt.org/z/ee4TcPY5K
The text was updated successfully, but these errors were encountered: