Partial ordering of constrained member functions
template<typename>
constexpr bool b = true;
template<typename T>
concept C = b<T>;
template<typename T, typename U>
class foo
{
public:
void bar() const requires C<T> {} // #1
void bar() const requires (C<T> && C<U>) {} // Subsumes #1
};
template<typename T, typename U>
void bar(foo<T, U> const &) requires C<T> {} // #2
template<typename T, typename U>
void bar(foo<T, U> const &) requires (C<T> && C<U>) {} // Subsumes #2
int main()
{
foo<int, int> x;
x.bar(); // Clang reports an ambiguity
bar(x); // Clang does not complain
return 0;
}
@llvm/issue-subscribers-clang-frontend
gobolt showing clang rejects and gcc accepts the code: https://godbolt.org/z/n1GsYKvGs
@erichkeane asked me what MSVC says and it agree with clang: https://godbolt.org/z/odc4E7h4e
If the member functions are templates:
template<typename>
constexpr bool b = true;
template<typename T>
concept C = b<T>;
template<typename T, typename U>
class foo
{
public:
template<typename = void>
void bar() const requires C<T> {} // #1
template<typename = void>
void bar() const requires (C<T> && C<U>) {} // Subsumes #1
};
template<typename T, typename U>
void bar(foo<T, U> const &) requires C<T> {} // #2
template<typename T, typename U>
void bar(foo<T, U> const &) requires (C<T> && C<U>) {} // Subsumes #2
int main()
{
foo<int, int> x;
x.bar(); // Clang reports an ambiguity
bar(x); // Clang does not complain
return 0;
}
then Clang trunk accepts the testcase, but Clang 15 rejects it.
Perhaps @erichkeane 's patch on deferred evaluation of constraints made a difference here.
Maybe? We HAVE had work done in the partial ordering of constrained functions since 15 though.
See https://reviews.llvm.org/D128750 Perhaps @yuanfang-chen has some opinions on it?
I think the test case should be accepted.
When picking the overloaded non-template function, constraints partial ordering applies by https://eel.is/c++draft/over.match.best#general-2.6
I believe this has been already fixed.
El vie, 14 oct 2022 a las 3:18, Yuanfang Chen @.***>) escribió:
I think the test case should be accepted.
When picking the overloaded non-template function, constraints partial ordering applied by https://eel.is/c++draft/over.match.best#general-2.6
— Reply to this email directly, view it on GitHub https://github.com/llvm/llvm-project/issues/58165#issuecomment-1278351489, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARCVZBG4DYCQBCOUEGCY7LTWDCYGPANCNFSM6AAAAAAQ5TVVOM . You are receiving this because you authored the thread.Message ID: @.***>
This has been fixed since clang 16.
https://godbolt.org/z/3vj5zP1ne