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