Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5db38ef

Browse files
committed
C++: Add a test for constexpr functions
1 parent a9f8a53 commit 5db38ef

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
constexpr int fun_constexpr();
3+
int fun_not_constexpr();
4+
5+
constexpr int overloaded_fun(int i) {
6+
return 5;
7+
}
8+
9+
int overloaded_fun(float f) {
10+
return 6;
11+
}
12+
13+
template <typename T>
14+
constexpr int template_fun(T t) {
15+
return overloaded_fun(t);
16+
}
17+
18+
void caller(void) {
19+
int i;
20+
float f;
21+
template_fun(i);
22+
template_fun(f);
23+
}
24+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| constexpr.cpp:2:15:2:27 | fun_constexpr | fun_constexpr() -> int | true | true |
2+
| constexpr.cpp:3:5:3:21 | fun_not_constexpr | fun_not_constexpr() -> int | false | false |
3+
| constexpr.cpp:5:15:5:28 | overloaded_fun | overloaded_fun(int) -> int | true | true |
4+
| constexpr.cpp:9:5:9:18 | overloaded_fun | overloaded_fun(float) -> int | false | false |
5+
| constexpr.cpp:14:15:14:15 | template_fun | template_fun<float>(float) -> int | true | false |
6+
| constexpr.cpp:14:15:14:15 | template_fun | template_fun<int>(int) -> int | true | true |
7+
| constexpr.cpp:14:15:14:26 | template_fun | template_fun<T>(T) -> int | true | true |
8+
| constexpr.cpp:18:6:18:11 | caller | caller() -> void | false | false |
9+
| file://:0:0:0:0 | operator= | __va_list_tag::operator=(__va_list_tag &&) -> __va_list_tag & | false | false |
10+
| file://:0:0:0:0 | operator= | __va_list_tag::operator=(const __va_list_tag &) -> __va_list_tag & | false | false |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cpp
2+
3+
from Function f
4+
select f, f.getFullSignature(),
5+
any(boolean b | if f.isDeclaredConstexpr() then b = true else b = false),
6+
any(boolean b | if f.isConstexpr() then b = true else b = false)

0 commit comments

Comments
 (0)