| 1 |
// P1169R4 - static operator() |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
// { dg-options "" } |
| 4 |
|
| 5 |
template <typename T> |
| 6 |
struct S |
| 7 |
{ |
| 8 |
static constexpr bool operator () (T const &x, T const &y) { return x < y; }; // { dg-warning "may be a static member function only with" "" { target c++20_down } } |
| 9 |
using P = bool (*) (T const &, T const &); |
| 10 |
operator P () const { return operator (); } |
| 11 |
}; |
| 12 |
|
| 13 |
static_assert (S<int> {} (1, 2), ""); |
| 14 |
|
| 15 |
template <typename T> |
| 16 |
void |
| 17 |
bar (T &x) |
| 18 |
{ |
| 19 |
x (1, 2); |
| 20 |
} |
| 21 |
|
| 22 |
void |
| 23 |
foo () |
| 24 |
{ |
| 25 |
#if __cpp_constexpr >= 201603L |
| 26 |
auto a = [](int x, int y) static constexpr { return x + y; }; // { dg-warning "'static' only valid in lambda with" "" { target { c++17 && c++20_down } } } |
| 27 |
static_assert (a (1, 2) == 3, ""); |
| 28 |
bar (*a); |
| 29 |
#endif |
| 30 |
auto b = []() static { return 1; }; // { dg-warning "'static' only valid in lambda with" "" { target c++20_down } } |
| 31 |
b (); |
| 32 |
auto c = [](int x, int y) static { return x + y; }; // { dg-warning "'static' only valid in lambda with" "" { target c++20_down } } |
| 33 |
c (1, 2); |
| 34 |
bar (*c); |
| 35 |
#if __cpp_generic_lambdas >= 201707L |
| 36 |
auto d = []<typename T, typename U>(T x, U y) static { return x + y; }; // { dg-warning "'static' only valid in lambda with" "" { target c++20_only } } |
| 37 |
d (1, 2L); |
| 38 |
#endif |
| 39 |
S<long> s; |
| 40 |
s(1L, 2L); |
| 41 |
} |