diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-11-08 05:07:16 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-11-08 05:07:16 +0000 |
commit | 0f0af19b058151690ec02d781d0039fb1fc38426 (patch) | |
tree | 628729499c9190870f32a30ddfea3d8c9db273fd /clang/test/CodeGenCXX/cxx1z-fold-expression.cpp | |
parent | 8f6dd44056ceb2821b7692f1a110f91866b1bf2b (diff) | |
download | bcm5719-llvm-0f0af19b058151690ec02d781d0039fb1fc38426.tar.gz bcm5719-llvm-0f0af19b058151690ec02d781d0039fb1fc38426.zip |
[c++1z] N4295: fold-expressions.
This is a new form of expression of the form:
(expr op ... op expr)
where one of the exprs is a parameter pack. It expands into
(expr1 op (expr2onwards op ... op expr))
(and likewise if the pack is on the right). The non-pack operand can be
omitted; in that case, an empty pack gives a fallback value or an error,
depending on the operator.
llvm-svn: 221573
Diffstat (limited to 'clang/test/CodeGenCXX/cxx1z-fold-expression.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/cxx1z-fold-expression.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/cxx1z-fold-expression.cpp b/clang/test/CodeGenCXX/cxx1z-fold-expression.cpp new file mode 100644 index 00000000000..7677fc0e18f --- /dev/null +++ b/clang/test/CodeGenCXX/cxx1z-fold-expression.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -std=c++1z -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s + +template<int> struct A {}; +template<int ...N> void foldr(A<(N + ...)>); +template<int ...N> void foldl(A<(... + N)>); +template<int ...N> void foldr1(A<(N + ... + 1)>); +template<int ...N> void foldl1(A<(1 + ... + N)>); +void use() { + foldr<1, 2, 3>({}); + foldl<1, 2, 3>({}); + foldr1<1, 2, 3>({}); + foldl1<1, 2, 3>({}); + // CHECK-DAG: @_Z5foldrIJLi1ELi2ELi3EEEv1AIXfrplT_EE( + // CHECK-DAG: @_Z5foldlIJLi1ELi2ELi3EEEv1AIXflplT_EE( + // CHECK-DAG: @_Z6foldr1IJLi1ELi2ELi3EEEv1AIXfxplT_Li1EEE( + // CHECK-DAG: @_Z6foldl1IJLi1ELi2ELi3EEEv1AIXfxplLi1ET_EE( +} + +template<int ...N> using Foldr = A<(N + ...)>; +template<int ...N> using Foldl = A<(... + N)>; +template<int ...N> using Foldr1 = A<(N + ... + 1)>; +template<int ...N> using Foldl1 = A<(1 + ... + N)>; + +template<int ...A> struct Partial { + template<int ...B> void foldr(Foldr<A..., B..., A..., B...>); + template<int ...B> void foldl(Foldr<A..., B..., A..., B...>); + template<int ...B> void foldr1(Foldr1<A..., B..., A..., B...>); + template<int ...B> void foldl1(Foldl1<A..., B..., A..., B...>); +}; +void use(Partial<1, 2> p) { + p.foldr<3, 4>({}); + p.foldl<3, 4>({}); + p.foldr1<3, 4>({}); + p.foldl1<3, 4>({}); + // CHECK-DAG: @_ZN7PartialIJLi1ELi2EEE5foldrIJLi3ELi4EEEEv1AIXplLi1EplLi2EfxplT_plLi1EplLi2EfrplT_EE( + // CHECK-DAG: @_ZN7PartialIJLi1ELi2EEE5foldlIJLi3ELi4EEEEv1AIXplLi1EplLi2EfxplT_plLi1EplLi2EfrplT_EE( + // CHECK-DAG: @_ZN7PartialIJLi1ELi2EEE6foldr1IJLi3ELi4EEEEv1AIXplLi1EplLi2EfxplT_plLi1EplLi2EfxplT_Li1EEE( + // CHECK-DAG: @_ZN7PartialIJLi1ELi2EEE6foldl1IJLi3ELi4EEEEv1AIXfxplplplfxplplplLi1ELi1ELi2ET_Li1ELi2ET_EE( +} + +extern int n; +template<int ...N> void f() { + (n = ... = N); +} +template void f<>(); |