annotate gcc/testsuite/g++.dg/cpp1z/constexpr-lambda6.C @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // Testcase from P0170R1
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 // { dg-do compile { target c++17 } }
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 auto monoid = [](auto v) { return [=] { return v; }; };
kono
parents:
diff changeset
5 auto add = [](auto m1) constexpr {
kono
parents:
diff changeset
6 auto ret = m1();
kono
parents:
diff changeset
7 return [=](auto m2) mutable {
kono
parents:
diff changeset
8 auto m1val = m1();
kono
parents:
diff changeset
9 auto plus = [=] (auto m2val) mutable constexpr
kono
parents:
diff changeset
10 { return m1val += m2val; };
kono
parents:
diff changeset
11 ret = plus(m2());
kono
parents:
diff changeset
12 return monoid(ret);
kono
parents:
diff changeset
13 };
kono
parents:
diff changeset
14 };
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 int main()
kono
parents:
diff changeset
17 {
kono
parents:
diff changeset
18 constexpr auto zero = monoid(0);
kono
parents:
diff changeset
19 constexpr auto one = monoid(1);
kono
parents:
diff changeset
20 static_assert(add(one)(zero)() == one()); // OK
kono
parents:
diff changeset
21 // Since 'two' below is not declared constexpr, an evaluation of its constexpr
kono
parents:
diff changeset
22 // member function call operator can not perform an lvalue-to-rvalue conversion
kono
parents:
diff changeset
23 // on one of its subobjects (that represents its capture) in a constant
kono
parents:
diff changeset
24 // expression.
kono
parents:
diff changeset
25 auto two = monoid(2);
kono
parents:
diff changeset
26 if (!(two() == 2)) __builtin_abort(); // OK, not a constant expression.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
27 static_assert(add(one)(one)() == two()); // { dg-error "|in .constexpr. expansion of " } two() is not a constant expression
111
kono
parents:
diff changeset
28 static_assert(add(one)(one)() == monoid(2)()); // OK
kono
parents:
diff changeset
29 }