| 1 | template<typename T> |
| 2 | int (T t1) { |
| 3 | return int(t1); |
| 4 | } |
| 5 | |
| 6 | // Some cases to cover ADL, we have two cases: |
| 7 | // |
| 8 | // - f which will have a overload in the global namespace if unqualified lookup |
| 9 | // find f(int) and f(T) is found via ADL. |
| 10 | // |
| 11 | // - g which does not have an overload in the global namespace. |
| 12 | namespace A { |
| 13 | struct C {}; |
| 14 | |
| 15 | template <typename T> int f(T) { return 4; } |
| 16 | |
| 17 | template <typename T> int g(T) { return 4; } |
| 18 | } // namespace A |
| 19 | |
| 20 | // Meant to overload A::f(T) which may be found via ADL |
| 21 | int f(int) { return 1; } |
| 22 | |
| 23 | // Regular overloaded functions case h(T) and h(double). |
| 24 | template <class T> int h(T x) { return x; } |
| 25 | int h(double d) { return 5; } |
| 26 | |
| 27 | template <class... Us> int var(Us... pargs) { return 10; } |
| 28 | |
| 29 | // Having the templated overloaded operators in a namespace effects the |
| 30 | // mangled name generated in the IR e.g. _ZltRK1BS1_ Vs _ZN1AltERKNS_1BES2_ |
| 31 | // One will be in the symbol table but the other won't. This results in a |
| 32 | // different code path that will result in CPlusPlusNameParser being used. |
| 33 | // This allows us to cover that code as well. |
| 34 | namespace A { |
| 35 | template <typename T> bool operator<(const T &, const T &) { return true; } |
| 36 | |
| 37 | template <typename T> bool operator>(const T &, const T &) { return true; } |
| 38 | |
| 39 | template <typename T> bool operator<<(const T &, const T &) { return true; } |
| 40 | |
| 41 | template <typename T> bool operator>>(const T &, const T &) { return true; } |
| 42 | |
| 43 | template <typename T> bool operator==(const T &, const T &) { return true; } |
| 44 | |
| 45 | struct B {}; |
| 46 | } // namespace A |
| 47 | |
| 48 | struct D {}; |
| 49 | |
| 50 | // Make sure we cover more straight forward cases as well. |
| 51 | bool operator<(const D &, const D &) { return true; } |
| 52 | bool operator>(const D &, const D &) { return true; } |
| 53 | bool operator>>(const D &, const D &) { return true; } |
| 54 | bool operator<<(const D &, const D &) { return true; } |
| 55 | bool operator==(const D &, const D &) { return true; } |
| 56 | |
| 57 | int main() { |
| 58 | A::B b1; |
| 59 | A::B b2; |
| 60 | D d1; |
| 61 | D d2; |
| 62 | |
| 63 | bool result_b = b1 < b2 && b1 << b2 && b1 == b2 && b1 > b2 && b1 >> b2; |
| 64 | bool result_c = d1 < d2 && d1 << d2 && d1 == d2 && d1 > d2 && d1 >> d2; |
| 65 | |
| 66 | return foo(t1: 42) + result_b + result_c + f(A::C{}) + g(A::C{}) + h(x: 10) + h(d: 1.) + |
| 67 | var(pargs: 1) + var(pargs: 1, pargs: 2); // break here |
| 68 | } |
| 69 | |