1 // RUN: %clang_cc1 -std=c++1z -verify %s
2
sum(T...t)3 template<typename ...T> constexpr auto sum(T ...t) { return (... + t); }
product(T...t)4 template<typename ...T> constexpr auto product(T ...t) { return (t * ...); }
all(T...t)5 template<typename ...T> constexpr auto all(T ...t) { return (true && ... && t); }
all2(T...t)6 template<typename ...T> constexpr auto all2(T ...t) { return (t && ... && true); }
7
8 int k1 = (1 + ... + 2); // expected-error {{does not contain any unexpanded parameter packs}}
9 int k2 = (1 + ...); // expected-error {{does not contain any unexpanded parameter packs}}
10 int k3 = (... + 2); // expected-error {{does not contain any unexpanded parameter packs}}
11
bad1()12 template<int ...N> void bad1() { (N + ... + N); } // expected-error {{unexpanded parameter packs in both operands}}
13 // FIXME: it would be reasonable to support this as an extension.
bad2()14 template<int ...N> void bad2() { (2 * N + ... + 1); } // expected-error {{expression not permitted as operand}}
bad3()15 template<int ...N> void bad3() { (2 + N * ... * 1); } // expected-error {{expression not permitted as operand}}
bad4(int (&...x)[N])16 template<int ...N, int ...M> void bad4(int (&...x)[N]) { (N + M * ... * 1); } // expected-error {{expression not permitted as operand}}
fixed4(int (&...x)[N])17 template<int ...N, int ...M> void fixed4(int (&...x)[N]) { ((N + M) * ... * 1); }
18
19 // Parens are mandatory.
bad5()20 template<int ...N> void bad5() { N + ...; } // expected-error {{expected expression}} expected-error +{{}}
bad6()21 template<int ...N> void bad6() { ... + N; } // expected-error {{expected expression}}
bad7()22 template<int ...N> void bad7() { N + ... + N; } // expected-error {{expected expression}} expected-error +{{}}
23
24 // Must have a fold-operator in the relevant places.
bad8()25 template<int ...N> int bad8() { return (N + ... * 3); } // expected-error {{operators in fold expression must be the same}}
bad9()26 template<int ...N> int bad9() { return (3 + ... * N); } // expected-error {{operators in fold expression must be the same}}
bad10()27 template<int ...N> int bad10() { return (3 ? ... : N); } // expected-error +{{}} expected-note {{to match}}
bad11()28 template<int ...N> int bad11() { return (N + ... 0); } // expected-error {{expected a foldable binary operator}} expected-error {{expected expression}}
bad12()29 template<int ...N> int bad12() { return (... N); } // expected-error {{expected expression}}
30