aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp1z/constexpr-lambda8.C
blob: 82351ff0c54bdf51c1b2cd66088dbfa44ea0ecd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Testcase from P0170R1
// { dg-do compile { target c++17 } }

auto Fwd = [](int (*fp)(int), auto a) { return fp(a); };
auto C = [](auto a) { return a; };
static_assert( Fwd(C ,3) == 3); // OK

// No specialization of the function call operator template can be constexpr
// (because of the local static).
auto NC = [](auto a) { static int s; return a; }; // { dg-error "static" }
// { dg-error "called in a constant expression" "" { target *-*-* } .-1 }

static_assert( Fwd(NC ,3) == 3); // { dg-error "" }
// { dg-message "operator int" "" { target *-*-* } .-1 }

// We look for the string "operator int" to check that we aren't trying to do
// template pretty-printing in an expression; that gets incredibly unwieldy
// with the decltype magic we do for lambdas.