diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 72cc7665ed4..955418f669a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-22 Marek Polacek + + PR c++/93807 + * g++.dg/cpp2a/fn-template20.C: New test. + 2020-04-22 Duan bo PR testsuite/94712 diff --git a/gcc/testsuite/g++.dg/cpp2a/fn-template20.C b/gcc/testsuite/g++.dg/cpp2a/fn-template20.C new file mode 100644 index 00000000000..c558ad1f2b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/fn-template20.C @@ -0,0 +1,34 @@ +// PR c++/93807 +// { dg-do compile { target c++11 } } + +// In C++17, we need the following declaration to treat operator== as +// a template name. In C++20, this is handled by [temp.names]/2. +#if __cplusplus <= 201703L +template +class Foo; +template +constexpr bool operator==(T lhs, const Foo& rhs); +#endif + +template +class Foo { +public: + constexpr Foo(T k) : mK(k) {} + + constexpr friend bool operator==(T lhs, const Foo& rhs); +private: + T mK; +}; + +template +constexpr bool +operator==(T lhs, const Foo& rhs) +{ + return lhs == rhs.mK; +} + +int +main () +{ + return 1 == Foo(1) ? 0 : 1; +}