diff options
Diffstat (limited to 'Tests/CompileFeatures')
47 files changed, 517 insertions, 0 deletions
diff --git a/Tests/CompileFeatures/CMakeLists.txt b/Tests/CompileFeatures/CMakeLists.txt new file mode 100644 index 0000000..ce5004b --- /dev/null +++ b/Tests/CompileFeatures/CMakeLists.txt @@ -0,0 +1,44 @@ + +cmake_minimum_required(VERSION 3.0) + +project(CompileFeatures) + +if (NOT CMAKE_CXX_COMPILE_FEATURES) + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp" + "int main(int,char**) { return 0; }\n" + ) + add_executable(CompileFeatures "${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp") + return() +endif() + +macro(run_test feature) + if (";${CMAKE_CXX_COMPILE_FEATURES};" MATCHES ${feature}) + add_library(test_${feature} OBJECT ${feature}.cpp) + set_property(TARGET test_${feature} + PROPERTY COMPILE_FEATURES "${feature}" + ) + else() + message("Not supported: ${feature}") + endif() +endmacro() + +foreach(feature ${CMAKE_CXX_KNOWN_FEATURES}) + run_test(${feature}) +endforeach() + +add_executable(CompileFeatures main.cpp) +set_property(TARGET CompileFeatures + PROPERTY COMPILE_FEATURES "cxx_auto_type" +) + +add_executable(GenexCompileFeatures main.cpp) +set_property(TARGET GenexCompileFeatures + PROPERTY COMPILE_FEATURES "$<1:cxx_auto_type>;$<0:not_a_feature>" +) + +add_library(iface INTERFACE) +set_property(TARGET iface + PROPERTY INTERFACE_COMPILE_FEATURES "cxx_auto_type" +) +add_executable(IfaceCompileFeatures main.cpp) +target_link_libraries(IfaceCompileFeatures iface) diff --git a/Tests/CompileFeatures/cxx_alias_templates.cpp b/Tests/CompileFeatures/cxx_alias_templates.cpp new file mode 100644 index 0000000..a47e27d --- /dev/null +++ b/Tests/CompileFeatures/cxx_alias_templates.cpp @@ -0,0 +1,11 @@ + +template <typename T1, typename T2> +struct A +{ + typedef T1 MyT1; + using MyT2 = T2; +}; + +using B = A<int, char>; +template<typename T> +using C = A<int, T>; diff --git a/Tests/CompileFeatures/cxx_alignas.cpp b/Tests/CompileFeatures/cxx_alignas.cpp new file mode 100644 index 0000000..35b7c82 --- /dev/null +++ b/Tests/CompileFeatures/cxx_alignas.cpp @@ -0,0 +1,4 @@ + +struct S1 { + alignas(8) int n; +}; diff --git a/Tests/CompileFeatures/cxx_alignof.cpp b/Tests/CompileFeatures/cxx_alignof.cpp new file mode 100644 index 0000000..63b14fe --- /dev/null +++ b/Tests/CompileFeatures/cxx_alignof.cpp @@ -0,0 +1,5 @@ + +int someFunc() +{ + return alignof(int); +} diff --git a/Tests/CompileFeatures/cxx_attributes.cpp b/Tests/CompileFeatures/cxx_attributes.cpp new file mode 100644 index 0000000..a3c89ea --- /dev/null +++ b/Tests/CompileFeatures/cxx_attributes.cpp @@ -0,0 +1,2 @@ + +void unusedFunc [[noreturn]] () { throw 1; } diff --git a/Tests/CompileFeatures/cxx_auto_type.cpp b/Tests/CompileFeatures/cxx_auto_type.cpp new file mode 100644 index 0000000..7dbf04f --- /dev/null +++ b/Tests/CompileFeatures/cxx_auto_type.cpp @@ -0,0 +1,5 @@ + +void someFunc() +{ + auto x = 3.14; +} diff --git a/Tests/CompileFeatures/cxx_constexpr.cpp b/Tests/CompileFeatures/cxx_constexpr.cpp new file mode 100644 index 0000000..570c10f --- /dev/null +++ b/Tests/CompileFeatures/cxx_constexpr.cpp @@ -0,0 +1,5 @@ + +constexpr int getNum() +{ + return 42; +} diff --git a/Tests/CompileFeatures/cxx_decltype.cpp b/Tests/CompileFeatures/cxx_decltype.cpp new file mode 100644 index 0000000..24ec51e --- /dev/null +++ b/Tests/CompileFeatures/cxx_decltype.cpp @@ -0,0 +1,7 @@ + +int someFunc() +{ + int i = 0; + decltype(i) other = 0; + return other; +} diff --git a/Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp b/Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp new file mode 100644 index 0000000..109d038 --- /dev/null +++ b/Tests/CompileFeatures/cxx_decltype_incomplete_return_types.cpp @@ -0,0 +1,14 @@ + +template<class T> +struct A +{ + ~A() = delete; +}; + +template<class T> auto h() -> A<T>; +template<class T> auto i(T) -> T; +template<class T> auto f(T) -> decltype(i(h<T>())); +template<class T> auto f(T) -> void; +auto g() -> void { + f(42); +} diff --git a/Tests/CompileFeatures/cxx_default_function_template_args.cpp b/Tests/CompileFeatures/cxx_default_function_template_args.cpp new file mode 100644 index 0000000..3d14c52 --- /dev/null +++ b/Tests/CompileFeatures/cxx_default_function_template_args.cpp @@ -0,0 +1,12 @@ + +template<typename T = int> +int someFunc() +{ + T t = 0; + return t; +} + +void otherFunc() +{ + someFunc(); +} diff --git a/Tests/CompileFeatures/cxx_defaulted_functions.cpp b/Tests/CompileFeatures/cxx_defaulted_functions.cpp new file mode 100644 index 0000000..b679a92 --- /dev/null +++ b/Tests/CompileFeatures/cxx_defaulted_functions.cpp @@ -0,0 +1,9 @@ + +struct A { + A() = default; +}; + +void someFunc() +{ + A a; +} diff --git a/Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp b/Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp new file mode 100644 index 0000000..14f9871 --- /dev/null +++ b/Tests/CompileFeatures/cxx_defaulted_move_initializers.cpp @@ -0,0 +1,7 @@ + +struct A +{ + A() = default; + A& operator=(A&&) = default; + A(A&&) = default; +}; diff --git a/Tests/CompileFeatures/cxx_delegating_constructors.cpp b/Tests/CompileFeatures/cxx_delegating_constructors.cpp new file mode 100644 index 0000000..4b41615 --- /dev/null +++ b/Tests/CompileFeatures/cxx_delegating_constructors.cpp @@ -0,0 +1,15 @@ + +class Foo +{ +public: + Foo(int i); + + Foo(double d) + : Foo(static_cast<int>(d)) + { + + } + +private: + int m_i; +}; diff --git a/Tests/CompileFeatures/cxx_deleted_functions.cpp b/Tests/CompileFeatures/cxx_deleted_functions.cpp new file mode 100644 index 0000000..4ecb1e9 --- /dev/null +++ b/Tests/CompileFeatures/cxx_deleted_functions.cpp @@ -0,0 +1,6 @@ + +struct A +{ + A(const A&) = delete; + A& operator=(const A&) = delete; +}; diff --git a/Tests/CompileFeatures/cxx_enum_forward_declarations.cpp b/Tests/CompileFeatures/cxx_enum_forward_declarations.cpp new file mode 100644 index 0000000..a7e1445 --- /dev/null +++ b/Tests/CompileFeatures/cxx_enum_forward_declarations.cpp @@ -0,0 +1,8 @@ + +enum SomeEnum : short; + +void someFunc() +{ + SomeEnum value; + int i = value; +} diff --git a/Tests/CompileFeatures/cxx_explicit_conversions.cpp b/Tests/CompileFeatures/cxx_explicit_conversions.cpp new file mode 100644 index 0000000..0decdcd --- /dev/null +++ b/Tests/CompileFeatures/cxx_explicit_conversions.cpp @@ -0,0 +1,10 @@ + +class A +{ + int m_i; +public: + explicit operator bool() + { + return m_i != 0; + } +}; diff --git a/Tests/CompileFeatures/cxx_extended_friend_declarations.cpp b/Tests/CompileFeatures/cxx_extended_friend_declarations.cpp new file mode 100644 index 0000000..631c699 --- /dev/null +++ b/Tests/CompileFeatures/cxx_extended_friend_declarations.cpp @@ -0,0 +1,25 @@ + +template <typename T> +struct B +{ + B() : m_i(42) {} +private: + int m_i; + friend T; +}; + +struct A +{ + template<typename T> + int getBValue(B<T> b) + { + return b.m_i; + } +}; + +void someFunc() +{ + A a; + B<A> b; + a.getBValue(b); +} diff --git a/Tests/CompileFeatures/cxx_extern_templates.cpp b/Tests/CompileFeatures/cxx_extern_templates.cpp new file mode 100644 index 0000000..9fa4aa4 --- /dev/null +++ b/Tests/CompileFeatures/cxx_extern_templates.cpp @@ -0,0 +1,12 @@ + +template<typename T> +void someFunc() +{ +} + +extern template void someFunc<int>(); + +void otherFunc() +{ + someFunc<int>(); +} diff --git a/Tests/CompileFeatures/cxx_final.cpp b/Tests/CompileFeatures/cxx_final.cpp new file mode 100644 index 0000000..598cb94 --- /dev/null +++ b/Tests/CompileFeatures/cxx_final.cpp @@ -0,0 +1,2 @@ + +struct A final {}; diff --git a/Tests/CompileFeatures/cxx_func_identifier.cpp b/Tests/CompileFeatures/cxx_func_identifier.cpp new file mode 100644 index 0000000..0c3595c --- /dev/null +++ b/Tests/CompileFeatures/cxx_func_identifier.cpp @@ -0,0 +1,6 @@ + +void someFunc() +{ + bool b = sizeof(__func__); + (void)b; +} diff --git a/Tests/CompileFeatures/cxx_generalized_initializers.cpp b/Tests/CompileFeatures/cxx_generalized_initializers.cpp new file mode 100644 index 0000000..8013ef5 --- /dev/null +++ b/Tests/CompileFeatures/cxx_generalized_initializers.cpp @@ -0,0 +1,23 @@ + +// Dummy implementation. Test only the compiler feature. +namespace std { + typedef decltype(sizeof(int)) size_t; + template <class _E> + class initializer_list + { + const _E* __begin_; + size_t __size_; + + }; +} + +template <typename T> +struct A +{ + A(std::initializer_list<T>) {} +}; + +void someFunc() +{ + A<int> as = { 1, 2, 3, 4 }; +} diff --git a/Tests/CompileFeatures/cxx_inheriting_constructors.cpp b/Tests/CompileFeatures/cxx_inheriting_constructors.cpp new file mode 100644 index 0000000..a83b624 --- /dev/null +++ b/Tests/CompileFeatures/cxx_inheriting_constructors.cpp @@ -0,0 +1,18 @@ + +struct A +{ + int m_i; + + A(int i) : m_i(i) {} +}; + +struct B : public A +{ + using A::A; +}; + +void someFunc() +{ + int i; + B b(i); +} diff --git a/Tests/CompileFeatures/cxx_inline_namespaces.cpp b/Tests/CompileFeatures/cxx_inline_namespaces.cpp new file mode 100644 index 0000000..59fa9c8 --- /dev/null +++ b/Tests/CompileFeatures/cxx_inline_namespaces.cpp @@ -0,0 +1,26 @@ +namespace Lib +{ +inline namespace Lib_1 +{ + template <typename T> class A; +} + +template <typename T> void g(T); +} + +struct MyClass { + +}; +namespace Lib +{ +template<> +class A<MyClass> { + +}; +} + +void someFunc() +{ + Lib::A<MyClass> a; + g(a); // ok, Lib is an associated namespace of A +} diff --git a/Tests/CompileFeatures/cxx_lambdas.cpp b/Tests/CompileFeatures/cxx_lambdas.cpp new file mode 100644 index 0000000..eecaa23 --- /dev/null +++ b/Tests/CompileFeatures/cxx_lambdas.cpp @@ -0,0 +1,5 @@ + +void someFunc() +{ + [](){}(); +} diff --git a/Tests/CompileFeatures/cxx_local_type_template_args.cpp b/Tests/CompileFeatures/cxx_local_type_template_args.cpp new file mode 100644 index 0000000..802ea7a --- /dev/null +++ b/Tests/CompileFeatures/cxx_local_type_template_args.cpp @@ -0,0 +1,21 @@ + +template <typename T> +class X { }; +template <typename T> +void f(T t) { } +struct {} unnamed_obj; +void f() { + struct A { }; + enum { e1 }; + typedef struct {} B; + B b; + X<A> x1; + X<A*> x2; + X<B> x3; + f(e1); + f(unnamed_obj); + f(b); + (void)x1; + (void)x2; + (void)x3; +} diff --git a/Tests/CompileFeatures/cxx_long_long_type.cpp b/Tests/CompileFeatures/cxx_long_long_type.cpp new file mode 100644 index 0000000..670324c --- /dev/null +++ b/Tests/CompileFeatures/cxx_long_long_type.cpp @@ -0,0 +1,5 @@ + +void someFunc() +{ + long long ll = 9223372036854775807LL; +} diff --git a/Tests/CompileFeatures/cxx_noexcept.cpp b/Tests/CompileFeatures/cxx_noexcept.cpp new file mode 100644 index 0000000..a3c05b8 --- /dev/null +++ b/Tests/CompileFeatures/cxx_noexcept.cpp @@ -0,0 +1,5 @@ + +void someFunc() noexcept +{ + +} diff --git a/Tests/CompileFeatures/cxx_nonstatic_member_init.cpp b/Tests/CompileFeatures/cxx_nonstatic_member_init.cpp new file mode 100644 index 0000000..6b7fa70 --- /dev/null +++ b/Tests/CompileFeatures/cxx_nonstatic_member_init.cpp @@ -0,0 +1,4 @@ +class A +{ + int m_i = 42; +}; diff --git a/Tests/CompileFeatures/cxx_nullptr.cpp b/Tests/CompileFeatures/cxx_nullptr.cpp new file mode 100644 index 0000000..96307df --- /dev/null +++ b/Tests/CompileFeatures/cxx_nullptr.cpp @@ -0,0 +1,10 @@ + +void someFunc(int*) +{ + +} + +void otherFunc() +{ + someFunc(nullptr); +} diff --git a/Tests/CompileFeatures/cxx_override.cpp b/Tests/CompileFeatures/cxx_override.cpp new file mode 100644 index 0000000..55bec13 --- /dev/null +++ b/Tests/CompileFeatures/cxx_override.cpp @@ -0,0 +1,7 @@ + +struct A { + virtual void doNothing() {} +}; +struct B : A { + void doNothing() override {} +}; diff --git a/Tests/CompileFeatures/cxx_range_for.cpp b/Tests/CompileFeatures/cxx_range_for.cpp new file mode 100644 index 0000000..892109e --- /dev/null +++ b/Tests/CompileFeatures/cxx_range_for.cpp @@ -0,0 +1,10 @@ + +void someFunc() +{ + int accumulated = 0; + int numbers[] = { 1, 2, 5 }; + for (int i : numbers) + { + accumulated += i; + } +} diff --git a/Tests/CompileFeatures/cxx_raw_string_literals.cpp b/Tests/CompileFeatures/cxx_raw_string_literals.cpp new file mode 100644 index 0000000..ea4d231 --- /dev/null +++ b/Tests/CompileFeatures/cxx_raw_string_literals.cpp @@ -0,0 +1,7 @@ + +void someFunc() +{ +const char p[] = R"(a\ +b +c)"; +} diff --git a/Tests/CompileFeatures/cxx_reference_qualified_functions.cpp b/Tests/CompileFeatures/cxx_reference_qualified_functions.cpp new file mode 100644 index 0000000..83a2361 --- /dev/null +++ b/Tests/CompileFeatures/cxx_reference_qualified_functions.cpp @@ -0,0 +1,11 @@ + +struct test{ + void f() & { } + void f() && { } +}; + +void someFunc(){ + test t; + t.f(); // lvalue + test().f(); // rvalue +} diff --git a/Tests/CompileFeatures/cxx_right_angle_brackets.cpp b/Tests/CompileFeatures/cxx_right_angle_brackets.cpp new file mode 100644 index 0000000..2713fd8 --- /dev/null +++ b/Tests/CompileFeatures/cxx_right_angle_brackets.cpp @@ -0,0 +1,12 @@ + +template<typename T> +struct A +{ + typedef T Result; +}; + +void someFunc() +{ + A<A<int>> object; + (void)object; +} diff --git a/Tests/CompileFeatures/cxx_rvalue_references.cpp b/Tests/CompileFeatures/cxx_rvalue_references.cpp new file mode 100644 index 0000000..787026a --- /dev/null +++ b/Tests/CompileFeatures/cxx_rvalue_references.cpp @@ -0,0 +1,5 @@ + +void someFunc(int&&) +{ + +} diff --git a/Tests/CompileFeatures/cxx_sizeof_member.cpp b/Tests/CompileFeatures/cxx_sizeof_member.cpp new file mode 100644 index 0000000..ae143d2 --- /dev/null +++ b/Tests/CompileFeatures/cxx_sizeof_member.cpp @@ -0,0 +1,10 @@ + +struct A +{ + int m_i; +}; + +int someFunc() +{ + return sizeof(A::m_i) > 0 ? 1 : 2; +} diff --git a/Tests/CompileFeatures/cxx_static_assert.cpp b/Tests/CompileFeatures/cxx_static_assert.cpp new file mode 100644 index 0000000..6aa8678 --- /dev/null +++ b/Tests/CompileFeatures/cxx_static_assert.cpp @@ -0,0 +1,2 @@ + +static_assert(true, "static_assert test"); diff --git a/Tests/CompileFeatures/cxx_strong_enums.cpp b/Tests/CompileFeatures/cxx_strong_enums.cpp new file mode 100644 index 0000000..6262456 --- /dev/null +++ b/Tests/CompileFeatures/cxx_strong_enums.cpp @@ -0,0 +1,7 @@ + +enum class Colors +{ + RedColor, + GreenColor, + BlueColor +}; diff --git a/Tests/CompileFeatures/cxx_thread_local.cpp b/Tests/CompileFeatures/cxx_thread_local.cpp new file mode 100644 index 0000000..1fb27e2 --- /dev/null +++ b/Tests/CompileFeatures/cxx_thread_local.cpp @@ -0,0 +1,2 @@ + +thread_local unsigned int rage = 1; diff --git a/Tests/CompileFeatures/cxx_trailing_return_types.cpp b/Tests/CompileFeatures/cxx_trailing_return_types.cpp new file mode 100644 index 0000000..01a76cb --- /dev/null +++ b/Tests/CompileFeatures/cxx_trailing_return_types.cpp @@ -0,0 +1,5 @@ + +auto someFunc() -> int +{ + return 42; +} diff --git a/Tests/CompileFeatures/cxx_unicode_literals.cpp b/Tests/CompileFeatures/cxx_unicode_literals.cpp new file mode 100644 index 0000000..a7b7df0 --- /dev/null +++ b/Tests/CompileFeatures/cxx_unicode_literals.cpp @@ -0,0 +1,3 @@ + +const char16_t lit_16[] = u"\u00DA"; +const char32_t lit_32[] = U"\u00DA"; diff --git a/Tests/CompileFeatures/cxx_uniform_initialization.cpp b/Tests/CompileFeatures/cxx_uniform_initialization.cpp new file mode 100644 index 0000000..82c76e2 --- /dev/null +++ b/Tests/CompileFeatures/cxx_uniform_initialization.cpp @@ -0,0 +1,9 @@ +struct A {}; +struct B { + B(A) {} +}; + +void Func() +{ + B b{A{}}; +} diff --git a/Tests/CompileFeatures/cxx_unrestricted_unions.cpp b/Tests/CompileFeatures/cxx_unrestricted_unions.cpp new file mode 100644 index 0000000..698fd61 --- /dev/null +++ b/Tests/CompileFeatures/cxx_unrestricted_unions.cpp @@ -0,0 +1,11 @@ + +struct point { + point() {} + point(int x, int y) : x_(x), y_(y) {} + int x_, y_; +}; +union u { + point p_; + int i_; + const char* s_; +}; diff --git a/Tests/CompileFeatures/cxx_user_literals.cpp b/Tests/CompileFeatures/cxx_user_literals.cpp new file mode 100644 index 0000000..9e5a588 --- /dev/null +++ b/Tests/CompileFeatures/cxx_user_literals.cpp @@ -0,0 +1,7 @@ + +long double operator "" _meters(long double); + +void someFunc() +{ + long double i = 1.2_meters; +} diff --git a/Tests/CompileFeatures/cxx_variadic_macros.cpp b/Tests/CompileFeatures/cxx_variadic_macros.cpp new file mode 100644 index 0000000..4d007a5 --- /dev/null +++ b/Tests/CompileFeatures/cxx_variadic_macros.cpp @@ -0,0 +1,12 @@ + +int someFunc(int, char, int) +{ + return 0; +} + +#define FUNC_WRAPPER(...) someFunc(__VA_ARGS__) + +void otherFunc() +{ + FUNC_WRAPPER(42, 'a', 7); +} diff --git a/Tests/CompileFeatures/cxx_variadic_templates.cpp b/Tests/CompileFeatures/cxx_variadic_templates.cpp new file mode 100644 index 0000000..1d5a706 --- /dev/null +++ b/Tests/CompileFeatures/cxx_variadic_templates.cpp @@ -0,0 +1,65 @@ +template<int I, int... Is> +struct Interface; + +template<int I> +struct Interface<I> +{ + static int accumulate() + { + return I; + } +}; + +template<int I, int... Is> +struct Interface +{ + static int accumulate() + { + return I + Interface<Is...>::accumulate(); + } +}; + +// Note: split this into a separate test if a +// cxx_variadic_template_template_parameters feature is added. + +template<typename T> +struct eval { + enum { + Matched = 0 + }; +}; + +template<template<typename...> class T, typename... U> +struct eval<T<U...> > { + enum { + Matched = 1 + }; +}; + +template<typename...> +struct A { + +}; +template<typename T> +struct B { + +}; +template<typename T, typename U> +struct C { + +}; +template<typename T, typename U, typename...> +struct D { + +}; + +// Note: This test assumes that a compiler supporting this feature +// supports static_assert. Add a workaround if that does not hold. +static_assert(eval<A<> >::Matched, "A Matches"); +static_assert(eval<A<int> >::Matched, "A Matches"); +static_assert(eval<A<int, char> >::Matched, "A Matches"); +static_assert(eval<B<int> >::Matched, "B Matches"); +static_assert(eval<C<int, char> >::Matched, "C Matches"); +static_assert(eval<D<int, char> >::Matched, "D Matches"); +static_assert(eval<D<int, char, bool> >::Matched, "D Matches"); +static_assert(eval<D<int, char, bool, double> >::Matched, "D Matches"); diff --git a/Tests/CompileFeatures/main.cpp b/Tests/CompileFeatures/main.cpp new file mode 100644 index 0000000..3a8e0fc --- /dev/null +++ b/Tests/CompileFeatures/main.cpp @@ -0,0 +1,6 @@ + +int main(int,char**) +{ + auto value = 0; + return value; +} |