mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
C++: Add a test for constexpr functions
This commit is contained in:
24
cpp/ql/test/library-tests/functions/constexpr/constexpr.cpp
Normal file
24
cpp/ql/test/library-tests/functions/constexpr/constexpr.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
constexpr int fun_constexpr();
|
||||
int fun_not_constexpr();
|
||||
|
||||
constexpr int overloaded_fun(int i) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
int overloaded_fun(float f) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr int template_fun(T t) {
|
||||
return overloaded_fun(t);
|
||||
}
|
||||
|
||||
void caller(void) {
|
||||
int i;
|
||||
float f;
|
||||
template_fun(i);
|
||||
template_fun(f);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
| constexpr.cpp:2:15:2:27 | fun_constexpr | fun_constexpr() -> int | true | true |
|
||||
| constexpr.cpp:3:5:3:21 | fun_not_constexpr | fun_not_constexpr() -> int | false | false |
|
||||
| constexpr.cpp:5:15:5:28 | overloaded_fun | overloaded_fun(int) -> int | true | true |
|
||||
| constexpr.cpp:9:5:9:18 | overloaded_fun | overloaded_fun(float) -> int | false | false |
|
||||
| constexpr.cpp:14:15:14:15 | template_fun | template_fun<float>(float) -> int | true | false |
|
||||
| constexpr.cpp:14:15:14:15 | template_fun | template_fun<int>(int) -> int | true | true |
|
||||
| constexpr.cpp:14:15:14:26 | template_fun | template_fun<T>(T) -> int | true | true |
|
||||
| constexpr.cpp:18:6:18:11 | caller | caller() -> void | false | false |
|
||||
| file://:0:0:0:0 | operator= | __va_list_tag::operator=(__va_list_tag &&) -> __va_list_tag & | false | false |
|
||||
| file://:0:0:0:0 | operator= | __va_list_tag::operator=(const __va_list_tag &) -> __va_list_tag & | false | false |
|
||||
@@ -0,0 +1,6 @@
|
||||
import cpp
|
||||
|
||||
from Function f
|
||||
select f, f.getFullSignature(),
|
||||
any(boolean b | if f.isDeclaredConstexpr() then b = true else b = false),
|
||||
any(boolean b | if f.isConstexpr() then b = true else b = false)
|
||||
Reference in New Issue
Block a user