1 // { dg-do run { target c++17 } }
3 // { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } }
7 // Check the semantics of a couple of operations to make sure
8 // that the expressions are formed correctly.
12 #define MAKE_FNS(name, op) \
13 template<typename... Ts> \
14 auto unary_left_ ## name (Ts... ts) { return (... op ts); } \
15 template<typename... Ts> \
16 auto unary_right_ ## name (Ts... ts) { return (ts op ...); } \
17 template<typename T, typename... Ts> \
18 auto binary_left_ ## name (T x, Ts... ts) { return (x op ... op ts); } \
19 template<typename T, typename... Ts> \
20 auto binary_right_ ## name (T x, Ts... ts) { return (ts op ... op x); }
26 // assert(unary_left_add() == 0);
27 assert(unary_left_add(1) == 1);
28 assert(unary_left_add(1, 2, 3) == 6);
30 // assert(unary_right_add() == 0);
31 assert(unary_right_add(1) == 1);
32 assert(unary_right_add(1, 2, 3) == 6);
34 assert(binary_left_add(1) == 1);
35 assert(binary_left_add(1, 1) == 2);
36 assert(binary_left_add(1, 1, 2, 3) == 7);
38 assert(binary_right_add(1) == 1);
39 assert(binary_right_add(1, 1) == 2);
40 assert(binary_right_add(1, 1, 2, 3) == 7);
42 // unary_left_sub(); // { dg-error "empty"}
43 assert(unary_left_sub(1) == 1);
44 assert(unary_left_sub(1, 2, 3) == -4);
46 // unary_right_sub(); // { dg-error "empty"}
47 assert(unary_right_sub(1) == 1);
48 assert(unary_right_sub(1, 2, 3) == 2);
50 assert(binary_left_sub(1) == 1);
51 assert(binary_left_sub(1, 1) == 0);
52 assert(binary_left_sub(1, 1, 2, 3) == -5);
54 assert(binary_right_sub(1) == 1);
55 assert(binary_right_sub(1, 1) == 0);
56 assert(binary_right_sub(1, 1, 2, 3) == 1);