From fd62945d36bbf71f42f6c08fea144200ad90a0fb Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 31 Oct 2017 20:29:22 +0000 Subject: Fix usage of right shift operator in fold expressions The right shift operator was not seen as a valid operator in a fold expression, which is PR32563. Patch by Nicolas Lesser ("Blitz Rakete")! llvm-svn: 317032 --- clang/test/Parser/cxx1z-fold-expressions.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'clang/test') diff --git a/clang/test/Parser/cxx1z-fold-expressions.cpp b/clang/test/Parser/cxx1z-fold-expressions.cpp index b1f7318e410..342f11555fa 100644 --- a/clang/test/Parser/cxx1z-fold-expressions.cpp +++ b/clang/test/Parser/cxx1z-fold-expressions.cpp @@ -43,3 +43,20 @@ template void as_operand_of_cast(int a, T ...t) { (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); -- cgit v1.2.3