mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
C++: test for fold expressions
This commit is contained in:
28
cpp/ql/test/library-tests/fold/fold.cpp
Normal file
28
cpp/ql/test/library-tests/fold/fold.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
// semmle-extractor-options: --edg --c++17
|
||||
|
||||
template<typename ...Args>
|
||||
int sum(Args&&... args) {
|
||||
return (args + ...);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
int product(Args&&... args) {
|
||||
return (... * args);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
bool all(Args&&... args) {
|
||||
return (args && ... && true);
|
||||
}
|
||||
|
||||
template<typename ...Args>
|
||||
bool any(Args&&... args) {
|
||||
return (false || ... || args);
|
||||
}
|
||||
|
||||
void f() {
|
||||
int x = sum(1, 2, 3, 4, 5);
|
||||
int y = product(2, 4, 6, 8);
|
||||
bool a = all(true, true, false, true);
|
||||
bool b = any(false, true, false, false);
|
||||
}
|
||||
4
cpp/ql/test/library-tests/fold/fold.expected
Normal file
4
cpp/ql/test/library-tests/fold/fold.expected
Normal file
@@ -0,0 +1,4 @@
|
||||
| fold.cpp:5:10:5:21 | ( pack + ... ) | + | fold.cpp:5:11:5:14 | args | <no init> |
|
||||
| fold.cpp:10:10:10:21 | ( ... * pack ) | * | fold.cpp:10:17:10:20 | args | <no init> |
|
||||
| fold.cpp:15:10:15:30 | ( pack && ... && init ) | && | fold.cpp:15:11:15:14 | args | 1 |
|
||||
| fold.cpp:20:10:20:31 | ( init \|\| ... \|\| pack ) | \|\| | fold.cpp:20:27:20:30 | args | 0 |
|
||||
7
cpp/ql/test/library-tests/fold/fold.ql
Normal file
7
cpp/ql/test/library-tests/fold/fold.ql
Normal file
@@ -0,0 +1,7 @@
|
||||
import cpp
|
||||
|
||||
from FoldExpr fe, Expr pack, string init
|
||||
where
|
||||
pack = fe.getPackExpr() and
|
||||
if fe.hasInitExpr() then init = fe.getInitExpr().toString() else init = "<no init>"
|
||||
select fe, fe.getOperatorString(), pack, init
|
||||
Reference in New Issue
Block a user