// RUN: %clang_cc1 -std=c++1z -verify %s template constexpr auto sum(T ...t) { return (... + t); } template constexpr auto product(T ...t) { return (t * ...); } template constexpr auto all(T ...t) { return (true && ... && t); } template constexpr auto all2(T ...t) { return (t && ... && true); } int k1 = (1 + ... + 2); // expected-error {{does not contain any unexpanded parameter packs}} int k2 = (1 + ...); // expected-error {{does not contain any unexpanded parameter packs}} int k3 = (... + 2); // expected-error {{does not contain any unexpanded parameter packs}} struct A { A(int); friend A operator+(A, A); A operator-(A); A operator()(A); A operator[](A); }; A operator*(A, A); template void bad1() { (N + ... + N); } // expected-error {{unexpanded parameter packs in both operands}} // FIXME: it would be reasonable to support this as an extension. template void bad2() { (2 * N + ... + 1); } // expected-error {{expression not permitted as operand}} template void bad3() { (2 + N * ... * 1); } // expected-error {{expression not permitted as operand}} template void bad4(int (&...x)[N]) { (N + M * ... * 1); } // expected-error {{expression not permitted as operand}} template void fixed4(int (&...x)[N]) { ((N + M) * ... * 1); } template void bad4a(T ...t) { (t * 2 + ... + 1); } // expected-error {{expression not permitted as operand}} template void bad4b() { (A(0) + A(N) + ...); } // expected-error {{expression not permitted as operand}} template void bad4c() { (A(0) - A(N) + ...); } // expected-error {{expression not permitted as operand}} template void bad4d() { (A(0)(A(0)) + ... + A(0)[A(N)]); } // Parens are mandatory. template void bad5() { N + ...; } // expected-error {{expected expression}} expected-error +{{}} template void bad6() { ... + N; } // expected-error {{expected expression}} template void bad7() { N + ... + N; } // expected-error {{expected expression}} expected-error +{{}} // Must have a fold-operator in the relevant places. template int bad8() { return (N + ... * 3); } // expected-error {{operators in fold expression must be the same}} template int bad9() { return (3 + ... * N); } // expected-error {{operators in fold expression must be the same}} template int bad10() { return (3 ? ... : N); } // expected-error +{{}} expected-note {{to match}} template int bad11() { return (N + ... 0); } // expected-error {{expected a foldable binary operator}} expected-error {{expected expression}} template int bad12() { return (... N); } // expected-error {{expected expression}} template void as_operand_of_cast(int a, T ...t) { return (int)(a + ... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}} (int)(t + ... + undeclared_junk) + // expected-error {{undeclared}} (int)(... + undeclared_junk) + // expected-error {{undeclared}} expected-error {{does not contain any unexpanded}} (int)(undeclared_junk + ...) + // expected-error {{undeclared}} (int)(a + ...); // expected-error {{does not contain any unexpanded}} } // fold-operator can be '>' or '>>'. template constexpr bool greaterThan() { return (N > ...); } template constexpr int rightShift() { return (N >> ...); } static_assert(greaterThan<2, 1>()); static_assert(rightShift<10, 1>() == 5); template constexpr auto Identity = V; // Support fold operators within templates. template constexpr int nestedFoldOperator() { return Identity<(Identity<0> >> ... >> N)> + Identity<(N >> ... >> Identity<0>)>; } static_assert(nestedFoldOperator<3, 1>() == 1);