Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/fn-template20.C

raw
1 // PR c++/93807
2 // { dg-do compile { target c++11 } }
3
4 // In C++17, we need the following declaration to treat operator== as
5 // a template name. In C++20, this is handled by [temp.names]/2.
6 #if __cplusplus <= 201703L
7 template <typename T>
8 class Foo;
9 template <typename T>
10 constexpr bool operator==(T lhs, const Foo<T>& rhs);
11 #endif
12
13 template <typename T>
14 class Foo {
15 public:
16 constexpr Foo(T k) : mK(k) {}
17
18 constexpr friend bool operator==<T>(T lhs, const Foo& rhs);
19 private:
20 T mK;
21 };
22
23 template <typename T>
24 constexpr bool
25 operator==(T lhs, const Foo<T>& rhs)
26 {
27 return lhs == rhs.mK;
28 }
29
30 int
31 main ()
32 {
33 return 1 == Foo<int>(1) ? 0 : 1;
34 }