C++: Add a test for constexpr functions

This commit is contained in:
Ian Lynagh
2019-01-25 11:38:27 +00:00
parent a9f8a53dac
commit 5db38ef14b
3 changed files with 40 additions and 0 deletions

View 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);
}

View File

@@ -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 |

View File

@@ -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)