From 29f3a74e46a61e3f9eb8fe39d3c4e6c8fe92b6be Mon Sep 17 00:00:00 2001 From: badair Date: Fri, 15 Apr 2016 17:16:39 -0500 Subject: [PATCH] Excluding MSVC from unsupported feature tests --- CMakeLists.txt | 26 +++--- example/bind_1.cpp | 9 +- example/bind_2.cpp | 9 +- .../can_invoke_constexpr_function_object.cpp | 9 +- .../can_invoke_constexpr_function_pointer.cpp | 9 +- ...voke_constexpr_member_function_pointer.cpp | 10 +- example/is_constexpr_function_object.cpp | 9 +- example/is_constexpr_function_pointer.cpp | 10 +- example/make_function.cpp | 7 ++ include/callable_traits/bind.hpp | 19 ++++ include/callable_traits/detail/arity.hpp | 1 + qtcreator/main/main.cpp | 91 ++----------------- qtcreator/project/project.pro | 2 + test/bind_1.cpp | 9 +- test/bind_2.cpp | 9 +- test/can_invoke_constexpr.cpp | 9 +- test/is_constexpr.cpp | 9 +- 17 files changed, 137 insertions(+), 110 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1c7308..5135bdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,22 +33,26 @@ endmacro() callable_traits_append_flag(callable_traits_HAS_WERROR -Werror) callable_traits_append_flag(callable_traits_HAS_WX -WX) -callable_traits_append_flag(callable_traits_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0) -callable_traits_append_flag(callable_traits_HAS_PEDANTIC -pedantic) -callable_traits_append_flag(callable_traits_HAS_STDCXX1Y -std=c++1y) callable_traits_append_flag(callable_traits_HAS_QUNUSED_ARGUMENTS -Qunused-arguments) callable_traits_append_flag(callable_traits_HAS_WNO_UNUSED_LOCAL_TYPEDEFS -Wno-unused-local-typedefs) callable_traits_append_flag(callable_traits_HAS_WWRITE_STRINGS -Wwrite-strings) -if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - callable_traits_append_flag(callable_traits_HAS_W3 -W3) - - #disable warning about symbol truncation. Doesn't matter, affected types are not linked - callable_traits_append_flag(callable_traits_HAS_WD4503 -wd4503) +if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") + #disable warning about symbol truncation. Doesn't matter, affected types are not linked + callable_traits_append_flag(callable_traits_HAS_WD4503 -wd4503) + callable_traits_append_flag(callable_traits_HAS_W3 -W3) else() - callable_traits_append_flag(callable_traits_HAS_W -W) - callable_traits_append_flag(callable_traits_HAS_WALL -Wall) - callable_traits_append_flag(callable_traits_HAS_WEXTRA -Wextra) + + #if not using clang-cl + if(NOT MSVC) + callable_traits_append_flag(callable_traits_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0) + callable_traits_append_flag(callable_traits_HAS_PEDANTIC -pedantic) + callable_traits_append_flag(callable_traits_HAS_STDCXX1Y -std=c++1y) + endif() + + callable_traits_append_flag(callable_traits_HAS_W -W) + callable_traits_append_flag(callable_traits_HAS_WALL -Wall) + callable_traits_append_flag(callable_traits_HAS_WEXTRA -Wextra) endif() #find_package(Boost) diff --git a/example/bind_1.cpp b/example/bind_1.cpp index a01b319..78a08a5 100644 --- a/example/bind_1.cpp +++ b/example/bind_1.cpp @@ -6,6 +6,12 @@ Distributed under the Boost Software License, Version 1.0. ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ bind_1 /* In this example, the last _1 placeholder in the bind @@ -16,7 +22,7 @@ because ScaryMonster is the narrowest of all _1 parameters. */ #include #include #include -#include +#include struct Vampire {}; struct Robot {}; @@ -78,3 +84,4 @@ int main() { return 0; } //] +#endif diff --git a/example/bind_2.cpp b/example/bind_2.cpp index 7ccc032..93628ff 100644 --- a/example/bind_2.cpp +++ b/example/bind_2.cpp @@ -6,12 +6,18 @@ Distributed under the Boost Software License, Version 1.0. ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ bind_2 #include #include #include #include -#include +#include struct Vampire {}; struct Robot {}; @@ -57,3 +63,4 @@ int main() { return 0; } //] +#endif diff --git a/example/can_invoke_constexpr_function_object.cpp b/example/can_invoke_constexpr_function_object.cpp index 6955e57..21b3a58 100644 --- a/example/can_invoke_constexpr_function_object.cpp +++ b/example/can_invoke_constexpr_function_object.cpp @@ -4,9 +4,15 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ can_invoke_constexpr_function_object #include -#include +#include // NOTE: Due to non-compliance in MSVC, can_invoke_constexpr // always return std::false_type on that compiler, which causes @@ -71,3 +77,4 @@ static_assert(!ct::can_invoke_constexpr(s), ""); int main() {} //] +#endif diff --git a/example/can_invoke_constexpr_function_pointer.cpp b/example/can_invoke_constexpr_function_pointer.cpp index fee8798..7d170cc 100644 --- a/example/can_invoke_constexpr_function_pointer.cpp +++ b/example/can_invoke_constexpr_function_pointer.cpp @@ -5,9 +5,15 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ can_invoke_constexpr_function_pointer #include -#include +#include namespace ct = callable_traits; @@ -37,3 +43,4 @@ static_assert(!ct::can_invoke_constexpr(eight_c{}, nullptr), ""); int main() {} //] +#endif diff --git a/example/can_invoke_constexpr_member_function_pointer.cpp b/example/can_invoke_constexpr_member_function_pointer.cpp index ec21480..f997662 100644 --- a/example/can_invoke_constexpr_member_function_pointer.cpp +++ b/example/can_invoke_constexpr_member_function_pointer.cpp @@ -1,4 +1,3 @@ - /*!<- Copyright (c) 2016 Barrett Adair @@ -6,9 +5,15 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ can_invoke_constexpr_member_function_pointer #include -#include +#include // NOTE: Due to non-compliance in MSVC, can_invoke_constexpr // always returns std::false_type on that compiler, which @@ -34,3 +39,4 @@ static_assert(!ct::can_invoke_constexpr(pmf_constant{}, foo{}), ""); int main() {} //] +#endif diff --git a/example/is_constexpr_function_object.cpp b/example/is_constexpr_function_object.cpp index 5ee9019..f956195 100644 --- a/example/is_constexpr_function_object.cpp +++ b/example/is_constexpr_function_object.cpp @@ -4,13 +4,19 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ is_constexpr_function_object /*`[warning When compiling in MSVC, `is_constexpr` always returns `std::false_type`, because MSVC cannot compile the logic that normally determines this.]*/ #include -#include +#include namespace ct = callable_traits; @@ -86,3 +92,4 @@ static_assert(!ct::is_constexpr(divide{0}), ""); int main() {} //] +#endif diff --git a/example/is_constexpr_function_pointer.cpp b/example/is_constexpr_function_pointer.cpp index ec433ca..2d54bad 100644 --- a/example/is_constexpr_function_pointer.cpp +++ b/example/is_constexpr_function_pointer.cpp @@ -1,4 +1,3 @@ - /*!<- Copyright (c) 2016 Barrett Adair @@ -6,9 +5,15 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ is_constexpr_function_pointer #include -#include +#include // NOTE: Due to non-compliance in MSVC, is_constexpr always // returns std::false_type on that compiler, which causes @@ -36,3 +41,4 @@ static_assert(!ct::is_constexpr(), ""); int main() {} //] +#endif diff --git a/example/make_function.cpp b/example/make_function.cpp index fccef64..ae5c70f 100644 --- a/example/make_function.cpp +++ b/example/make_function.cpp @@ -4,6 +4,12 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) ->*/ +#include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + //[ make_function #include #include @@ -94,3 +100,4 @@ int main() { assert(f(99, 1) == 100); } //] +#endif diff --git a/include/callable_traits/bind.hpp b/include/callable_traits/bind.hpp index 5f1a1c0..56f0a95 100644 --- a/include/callable_traits/bind.hpp +++ b/include/callable_traits/bind.hpp @@ -17,6 +17,22 @@ Distributed under the Boost Software License, Version 1.0. namespace callable_traits { +#ifdef CALLABLE_TRAITS_MSVC + +template +inline constexpr int +bind(T&&...) { + + static_assert(MsvcAllowed, + "The native Microsoft Visual C++ compiler cannot " + "compile callable_traits::bind. To use this feature " + "in Windows, compile with Clang-cl or MinGW instead."); + + return -1; +} + +#else + template inline constexpr auto bind(T&& t, Args&&... args) -> @@ -27,6 +43,9 @@ namespace callable_traits { ::std::forward(args)... }; } + +#endif //#ifdef CALLABLE_TRAITS_MSVC + } #endif diff --git a/include/callable_traits/detail/arity.hpp b/include/callable_traits/detail/arity.hpp index 4f02738..2f95d3e 100644 --- a/include/callable_traits/detail/arity.hpp +++ b/include/callable_traits/detail/arity.hpp @@ -14,6 +14,7 @@ Distributed under the Boost Software License, Version 1.0. #include #include #include +#include namespace callable_traits { diff --git a/qtcreator/main/main.cpp b/qtcreator/main/main.cpp index 8dc8ae4..7e15752 100644 --- a/qtcreator/main/main.cpp +++ b/qtcreator/main/main.cpp @@ -4,93 +4,16 @@ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt) ->*/ -//[ make_function -#include -#include -#include +//[ push_args_back +#include -namespace example_library { - - namespace ct = callable_traits; - - // make_function turns a non-overloaded callable into a type-erased std::function object - template - inline decltype(auto) make_function(T&& t) { - - // callable_traits::function_type decays any non-overloaded callable type to - // a plain function type, which is structured in terms of INVOKE. - - using f = ct::function_type; - using result_type = std::function; - return result_type{ std::forward(t) }; - } - - // this make_function overload turns a bind expression into a type-erased std::function object - template - inline decltype(auto) make_function(T&& t, First&& first, Others&&... others) { - - // callable_traits::bind is essentially a compile-time parser of placeholder - // expressions, for the purpose of retaining more type information than - // std::bind normally allows - specifically, callable_traits::bind is used to - // determine the de-facto signature of the std::bind return type, with special - // considerations for conversions between reused placeholders and nested - // placeholder expressions. For the sake of convenience, callable_traits::bind - // is also a thin forwarding wrapper around std::bind (which is the only true - // runtime element in CallableTraits). - - using bind_expr = decltype(ct::bind( - std::forward(t), - std::forward(first), - std::forward(others)... - )); - - using f = ct::function_type; - using result_type = std::function; - - return result_type{ std::bind( - std::forward(t), - std::forward(first), - std::forward(others)... - )}; - } -} - -// client code starts here -#include - -using namespace example_library; -using namespace std::placeholders; - -int add(int i, int j) { - return i + j; -} - -struct adder { - - int eval(int i, int j) const { - return i + j; - } -}; +namespace ct = callable_traits; int main() { - // function pointer - auto f = make_function(&add); - assert(f(99, 1) == 100); - - // function reference - f = make_function(add); - assert(f(99, 1) == 100); - - // member function pointer (bound to object) - f = make_function(&adder::eval, adder{}, _1, _2); - assert(f(99, 1) == 100); - - // lambda - f = make_function([](int i, int j) { - return i + j; - }); - - assert(f(99, 1) == 100); + using f = void(int, char); + using test = ct::push_args_back; + using expect = void(int, char, long, void*); + static_assert(std::is_same::value, ""); } //] diff --git a/qtcreator/project/project.pro b/qtcreator/project/project.pro index 1f8b5d2..c8eeab0 100644 --- a/qtcreator/project/project.pro +++ b/qtcreator/project/project.pro @@ -2,3 +2,5 @@ TEMPLATE = aux CONFIG -= qt OTHER_FILES += ../../* +OTHER_FILES += ../../cmake/* + diff --git a/test/bind_1.cpp b/test/bind_1.cpp index 9a71051..f4f6fcc 100644 --- a/test/bind_1.cpp +++ b/test/bind_1.cpp @@ -15,6 +15,11 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + #ifndef CT_ASSERT #define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) #endif //CT_ASSERT @@ -145,6 +150,6 @@ int main() { using expected_args = std::tuple; CT_ASSERT(std::is_same::value); } - - return 0; } + +#endif diff --git a/test/bind_2.cpp b/test/bind_2.cpp index 825b32d..8d59f9c 100644 --- a/test/bind_2.cpp +++ b/test/bind_2.cpp @@ -15,6 +15,11 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + #ifndef CT_ASSERT #define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) #endif //CT_ASSERT @@ -138,6 +143,6 @@ int main() { CT_ASSERT(std::is_same::value); CT_RUNTIME_ASSERT(apply(ct_bind, expected_args{}) == "ABCDEFG"); CT_RUNTIME_ASSERT(apply(std_bind, expected_args{}) == "ABCDEFG"); - - return 0; } + +#endif diff --git a/test/can_invoke_constexpr.cpp b/test/can_invoke_constexpr.cpp index 08e7263..81636e8 100644 --- a/test/can_invoke_constexpr.cpp +++ b/test/can_invoke_constexpr.cpp @@ -8,6 +8,11 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + #ifndef CT_ASSERT #define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) #endif //CT_ASSERT @@ -59,4 +64,6 @@ CT_ASSERT(!ct::can_invoke_constexpr(foo1_pmf{}, foo1{}, 0)); CT_ASSERT(!ct::can_invoke_constexpr(foo3_pmf{}, foo3{})); CT_ASSERT( ct::can_invoke_constexpr(foo3_pmf{}, foo3{}, 0)); -int main() { return 0; } +int main() {} + +#endif diff --git a/test/is_constexpr.cpp b/test/is_constexpr.cpp index d9276b6..d02d4cb 100644 --- a/test/is_constexpr.cpp +++ b/test/is_constexpr.cpp @@ -8,6 +8,11 @@ Distributed under the Boost Software License, Version 1.0. #include #include +#ifdef CALLABLE_TRAITS_MSVC +//feature is unsupported in MSVC +int main(){ return 0; }; +#else + #ifndef CT_ASSERT #define CT_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) #endif //CT_ASSERT @@ -164,4 +169,6 @@ namespace test7 { CT_ASSERT(!ct::is_constexpr()); } -int main() { return 0; } +int main() {} + +#endif