diff options
Diffstat (limited to 'cmake/cmake-cxx11/Modules/CheckCXX11Features')
21 files changed, 311 insertions, 0 deletions
diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-__func__.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-__func__.cpp new file mode 100644 index 00000000..3bfd8a89 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-__func__.cpp @@ -0,0 +1,8 @@ +int main(void) +{ + if (!__func__) + return 1; + if (!(*__func__)) + return 1; + return 0; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto.cpp new file mode 100644 index 00000000..948648e9 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto.cpp @@ -0,0 +1,12 @@ + +int main() +{ + auto i = 5; + auto f = 3.14159f; + auto d = 3.14159; + bool ret = ( + (sizeof(f) < sizeof(d)) && + (sizeof(i) == sizeof(int)) + ); + return ret ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp new file mode 100644 index 00000000..3c0e3f2e --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto_fail_compile.cpp @@ -0,0 +1,7 @@ +int main(void) +{ + // must fail because there is no initializer + auto i; + + return 0; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp new file mode 100644 index 00000000..937b6835 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-auto_ret_type.cpp @@ -0,0 +1,8 @@ +auto foo(int i) -> int { + return i - 1; +} + +int main() +{ + return foo(1); +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp new file mode 100644 index 00000000..f5870b19 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-class_override_final.cpp @@ -0,0 +1,21 @@ +class base { +public: + virtual int foo(int a) + { return 4 + a; } + int bar(int a) final + { return a - 2; } +}; + +class sub final : public base { +public: + virtual int foo(int a) override + { return 8 + 2 * a; }; +}; + +int main(void) +{ + base b; + sub s; + + return (b.foo(2) * 2 == s.foo(2)) ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp new file mode 100644 index 00000000..bc00b278 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-class_override_final_fail_compile.cpp @@ -0,0 +1,25 @@ +class base { +public: + virtual int foo(int a) + { return 4 + a; } + virtual int bar(int a) final + { return a - 2; } +}; + +class sub final : public base { +public: + virtual int foo(int a) override + { return 8 + 2 * a; }; + virtual int bar(int a) + { return a; } +}; + +class impossible : public sub { }; + +int main(void) +{ + base b; + sub s; + + return 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp new file mode 100644 index 00000000..ed624512 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-constexpr.cpp @@ -0,0 +1,19 @@ +constexpr int square(int x) +{ + return x*x; +} + +constexpr int the_answer() +{ + return 42; +} + +int main() +{ + int test_arr[square(3)]; + bool ret = ( + (square(the_answer()) == 1764) && + (sizeof(test_arr)/sizeof(test_arr[0]) == 9) + ); + return ret ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp new file mode 100644 index 00000000..ca2c72dd --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-cstdint.cpp @@ -0,0 +1,11 @@ +#include <cstdint> + +int main() +{ + bool test = + (sizeof(int8_t) == 1) && + (sizeof(int16_t) == 2) && + (sizeof(int32_t) == 4) && + (sizeof(int64_t) == 8); + return test ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-decltype.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-decltype.cpp new file mode 100644 index 00000000..0dbb1cc5 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-decltype.cpp @@ -0,0 +1,10 @@ +bool check_size(int i) +{ + return sizeof(int) == sizeof(decltype(i)); +} + +int main() +{ + bool ret = check_size(42); + return ret ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp new file mode 100644 index 00000000..35e6c384 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-initializer_list.cpp @@ -0,0 +1,27 @@ +#include <vector> + +class seq { +public: + seq(std::initializer_list<int> list); + + int length() const; +private: + std::vector<int> m_v; +}; + +seq::seq(std::initializer_list<int> list) + : m_v(list) +{ +} + +int seq::length() const +{ + return m_v.size(); +} + +int main(void) +{ + seq a = {18, 20, 2, 0, 4, 7}; + + return (a.length() == 6) ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-lambda.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-lambda.cpp new file mode 100644 index 00000000..4c33ed58 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-lambda.cpp @@ -0,0 +1,5 @@ +int main() +{ + int ret = 0; + return ([&ret]() -> int { return ret; })(); +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-long_long.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-long_long.cpp new file mode 100644 index 00000000..09111275 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-long_long.cpp @@ -0,0 +1,7 @@ +int main(void) +{ + long long l; + unsigned long long ul; + + return ((sizeof(l) >= 8) && (sizeof(ul) >= 8)) ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp new file mode 100644 index 00000000..9f410715 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-nullptr.cpp @@ -0,0 +1,6 @@ +int main(void) +{ + void *v = nullptr; + + return v ? 1 : 0; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp new file mode 100644 index 00000000..6a002bcb --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-nullptr_fail_compile.cpp @@ -0,0 +1,6 @@ +int main(void) +{ + int i = nullptr; + + return 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-regex.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-regex.cpp new file mode 100644 index 00000000..2fe01c4f --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-regex.cpp @@ -0,0 +1,26 @@ +#include <algorithm> +#include <regex> + +int parse_line(std::string const& line) +{ + std::string tmp; + if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V")); + } else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V")); + } else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V")); + } else { + tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V")); + } + return static_cast<int>(std::count(tmp.begin(), tmp.end(), 'V')); +} + +int main() +{ + bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) && + (parse_line("f 7//7 3//-3 -2//2") == 3) && + (parse_line("f 7/7 3/-3 -2/2") == 3) && + (parse_line("f 7 3 -2") == 3); + return test ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp new file mode 100644 index 00000000..e6e7e5a9 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-rvalue-references.cpp @@ -0,0 +1,57 @@ +#include <cassert> + +class rvmove { +public: + void *ptr; + char *array; + + rvmove() + : ptr(0), + array(new char[10]) + { + ptr = this; + } + + rvmove(rvmove &&other) + : ptr(other.ptr), + array(other.array) + { + other.array = 0; + other.ptr = 0; + } + + ~rvmove() + { + assert(((ptr != 0) && (array != 0)) || ((ptr == 0) && (array == 0))); + delete[] array; + } + + rvmove &operator=(rvmove &&other) + { + delete[] array; + ptr = other.ptr; + array = other.array; + other.array = 0; + other.ptr = 0; + return *this; + } + + static rvmove create() + { + return rvmove(); + } +private: + rvmove(const rvmove &); + rvmove &operator=(const rvmove &); +}; + +int main() +{ + rvmove mine; + if (mine.ptr != &mine) + return 1; + mine = rvmove::create(); + if (mine.ptr == &mine) + return 1; + return 0; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp new file mode 100644 index 00000000..4902fc73 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-sizeof_member.cpp @@ -0,0 +1,14 @@ +struct foo { + char bar; + int baz; +}; + +int main(void) +{ + bool ret = ( + (sizeof(foo::bar) == 1) && + (sizeof(foo::baz) >= sizeof(foo::bar)) && + (sizeof(foo) >= sizeof(foo::bar) + sizeof(foo::baz)) + ); + return ret ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp new file mode 100644 index 00000000..0348c2ce --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-sizeof_member_fail.cpp @@ -0,0 +1,9 @@ +struct foo { + int baz; + double bar; +}; + +int main(void) +{ + return (sizeof(foo::bar) == 4) ? 0 : 1; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp new file mode 100644 index 00000000..47c2fefb --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-static_assert.cpp @@ -0,0 +1,5 @@ +int main(void) +{ + static_assert(0 < 1, "your ordering of integers is screwed"); + return 0; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp new file mode 100644 index 00000000..362fcdde --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-static_assert_fail_compile.cpp @@ -0,0 +1,5 @@ +int main(void) +{ + static_assert(1 < 0, "your ordering of integers is screwed"); + return 0; +} diff --git a/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp new file mode 100644 index 00000000..4518e886 --- /dev/null +++ b/cmake/cmake-cxx11/Modules/CheckCXX11Features/cxx11-test-variadic_templates.cpp @@ -0,0 +1,23 @@ +int Accumulate() +{ + return 0; +} + +template<typename T, typename... Ts> +int Accumulate(T v, Ts... vs) +{ + return v + Accumulate(vs...); +} + +template<int... Is> +int CountElements() +{ + return sizeof...(Is); +} + +int main() +{ + int acc = Accumulate(1, 2, 3, 4, -5); + int count = CountElements<1,2,3,4,5>(); + return ((acc == 5) && (count == 5)) ? 0 : 1; +} |