diff --git a/3rd_party/nonius/html_group_reporter.h b/3rd_party/nonius/html_group_reporter.h index 8c70b59e..8e3f4c38 100644 --- a/3rd_party/nonius/html_group_reporter.h +++ b/3rd_party/nonius/html_group_reporter.h @@ -258,10 +258,10 @@ namespace nonius { void print_outliers(outlier_classification o) { std::cout << "found " << o.total() << " outliers among " << o.samples_seen << " samples (" << detail::percentage_ratio(o.total(), o.samples_seen) << ")\n"; if(verbose) { - std::cout << "low severe", o.low_severe, o.samples_seen; - std::cout << "low mild", o.low_mild, o.samples_seen; - std::cout << "high mild", o.high_mild, o.samples_seen; - std::cout << "high severe", o.high_severe, o.samples_seen; + std::cout << "low severe" << o.low_severe << " " << o.samples_seen; + std::cout << "low mild" << o.low_mild << " " << o.samples_seen; + std::cout << "high mild" << o.high_mild << " " << o.samples_seen; + std::cout << "high severe" << o.high_severe << " " << o.samples_seen; } } void print_statistic_estimate(const char* name, estimate estimate) { diff --git a/CMake/config.cmake b/CMake/config.cmake index 62e8c583..1d753b36 100644 --- a/CMake/config.cmake +++ b/CMake/config.cmake @@ -89,6 +89,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() endif() +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + message(STATUS "added flag -std=c++11 to g++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden") + message(WARNING "clang support is currently experimental") +endif() + # RelWithDepInfo should have the same option like the Release build @@ -99,6 +106,9 @@ if(MSVC) elseif(CMAKE_COMPILER_IS_GNUCXX ) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g") else() message(WARNING "Please adjust CMAKE_CXX_FLAGS_RELWITHDEBINFO flags for this compiler!") endif() diff --git a/CMake/utility.cmake b/CMake/utility.cmake index d089adb5..9dbc172b 100644 --- a/CMake/utility.cmake +++ b/CMake/utility.cmake @@ -415,7 +415,13 @@ macro(enable_rtti _ENABLE) set(enable_rtti_opt "/GR") set(disable_rtti_opt "/GR-") elseif(CMAKE_COMPILER_IS_GNUCXX ) + set(enable_rtti_opt "-frtti") set(disable_rtti_opt "-fno-rtti") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(enable_rtti_opt "-frtti") + set(disable_rtti_opt "-fno-rtti") + else() + message(FATAL_ERROR "Don't know how to enable/disable RTTI for this compiler.") endif() if (${_ENABLE}) @@ -452,6 +458,8 @@ function(getCompilerName _COMPILER_NAME) string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${GCC_VERSION_OUTPUT}") set(COMPILER_NAME ${COMPILER_NAME}${GCC_VERSION}) endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(COMPILER_NAME "clang") else() message(WARNING "Can not retrieve compiler name!") return() diff --git a/src/benchmarks/bench_method/bench_find_method.cpp b/src/benchmarks/bench_method/bench_find_method.cpp index 0fc74b4b..f9e78d95 100644 --- a/src/benchmarks/bench_method/bench_find_method.cpp +++ b/src/benchmarks/bench_method/bench_find_method.cpp @@ -68,7 +68,7 @@ nonius::benchmark bench_rttr_find_method_level_1() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_1")) + if ((m = rttr::type::get(obj_base).get_method("method_1"))) { value = 1; } @@ -110,7 +110,7 @@ nonius::benchmark bench_rttr_find_method_level_3() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_3")) + if ((m = rttr::type::get(obj_base).get_method("method_3"))) { value = 1; } @@ -152,7 +152,7 @@ nonius::benchmark bench_rttr_find_method_level_6() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_6")) + if ((m = rttr::type::get(obj_base).get_method("method_6"))) { value = 1; } @@ -196,7 +196,7 @@ nonius::benchmark bench_rttr_find_method_neg_level_1() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_2")) + if ((m = rttr::type::get(obj_base).get_method("method_2"))) { value = 1; } @@ -238,7 +238,7 @@ nonius::benchmark bench_rttr_find_method_neg_level_3() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_4")) + if ((m = rttr::type::get(obj_base).get_method("method_4"))) { value = 1; } @@ -281,7 +281,7 @@ nonius::benchmark bench_rttr_find_method_neg_level_6() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_7")) + if ((m = rttr::type::get(obj_base).get_method("method_7"))) { value = 1; } @@ -324,7 +324,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_level_1() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_13")) //method 13 is contained in 'class_multiple_1C' + if ((m = rttr::type::get(obj_base).get_method("method_13"))) //method 13 is contained in 'class_multiple_1C' { value = 1; } @@ -366,7 +366,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_level_3() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_15")) //method 15 is contained in 'class_multiple_3C' + if ((m = rttr::type::get(obj_base).get_method("method_15"))) //method 15 is contained in 'class_multiple_3C' { value = 1; } @@ -408,7 +408,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_level_6() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_18")) //method 18 is contained in 'class_multiple_final' + if ((m = rttr::type::get(obj_base).get_method("method_18"))) //method 18 is contained in 'class_multiple_final' { value = 1; } @@ -452,7 +452,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_neg_level_1() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_13")) //method 13 is contained in 'class_multiple_1C' + if ((m = rttr::type::get(obj_base).get_method("method_13"))) //method 13 is contained in 'class_multiple_1C' { value = 1; } @@ -494,7 +494,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_neg_level_3() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_15")) //method 15 is contained in 'class_multiple_3C' + if ((m = rttr::type::get(obj_base).get_method("method_15"))) //method 15 is contained in 'class_multiple_3C' { value = 1; } @@ -536,7 +536,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_neg_level_6() rttr::method m = rttr::type::get(nullptr).get_method(""); meter.measure([&]() { - if (m = rttr::type::get(obj_base).get_method("method_19")) //method 19 is contained in 'class_multiple_final_D' + if ((m = rttr::type::get(obj_base).get_method("method_19"))) //method 19 is contained in 'class_multiple_final_D' { value = 1; } diff --git a/src/rttr/detail/base/core_prerequisites.h b/src/rttr/detail/base/core_prerequisites.h index 050f658e..67c84795 100644 --- a/src/rttr/detail/base/core_prerequisites.h +++ b/src/rttr/detail/base/core_prerequisites.h @@ -38,6 +38,7 @@ namespace rttr #define RTTR_COMPILER_MSVC 1 #define RTTR_COMPILER_GNUC 2 +#define RTTR_COMPILER_CLANG 3 #define RTTR_ENDIAN_LITTLE 1 #define RTTR_ENDIAN_BIG 2 @@ -57,7 +58,12 @@ namespace rttr ///////////////////////////////////////////////////////////////////////////////////////// // Compiler ///////////////////////////////////////////////////////////////////////////////////////// -#if defined( __GNUC__ ) +#if defined( __clang__ ) +# define RTTR_COMPILER RTTR_COMPILER_CLANG +# define RTTR_COMP_VER (((__clang_major__)*100) + \ + (__clang_minor__*10) + \ + __clang_patchlevel__) +#elif defined( __GNUC__ ) # define RTTR_COMPILER RTTR_COMPILER_GNUC # define RTTR_COMP_VER (((__GNUC__)*1000) + \ (__GNUC_MINOR__*100) + \ @@ -86,6 +92,9 @@ namespace rttr #elif RTTR_COMPILER == RTTR_COMPILER_GNUC # define RTTR_INLINE inline # define RTTR_FORCE_INLINE inline __attribute__((always_inline)) +#elif RTTR_COMPILER == RTTR_COMPILER_CLANG +# define RTTR_INLINE inline +# define RTTR_FORCE_INLINE inline __attribute__((always_inline)) #else # define RTTR_INLINE inline # define RTTR_FORCE_INLINE inline // no force inline for other platforms possible @@ -108,6 +117,10 @@ namespace rttr # define RTTR_HELPER_DLL_EXPORT # define RTTR_HELPER_DLL_LOCAL # endif +#elif RTTR_COMPILER == RTTR_COMPILER_CLANG +# define RTTR_HELPER_DLL_IMPORT __attribute__ ((visibility ("default"))) +# define RTTR_HELPER_DLL_EXPORT __attribute__ ((visibility ("default"))) +# define RTTR_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden"))) #else # error "Do not know how to export classes for this platform" #endif diff --git a/src/rttr/detail/conversion/number_conversion.h b/src/rttr/detail/conversion/number_conversion.h index 227903de..a83b1ff8 100644 --- a/src/rttr/detail/conversion/number_conversion.h +++ b/src/rttr/detail/conversion/number_conversion.h @@ -63,7 +63,7 @@ typename std::enable_if::value && bool>::type convert_to(const F& from, T& to) { - if (from < 0 || (sizeof(T) < sizeof(F)) && (from > static_cast(std::numeric_limits::max()))) + if ((from < 0) || ((sizeof(T) < sizeof(F)) && (from > static_cast(std::numeric_limits::max())))) return false; // value too large else if (static_cast(from) > std::numeric_limits::max()) return false; // value too large diff --git a/src/rttr/detail/type/type_impl.h b/src/rttr/detail/type/type_impl.h index ef1374c9..8ebab60f 100644 --- a/src/rttr/detail/type/type_impl.h +++ b/src/rttr/detail/type/type_impl.h @@ -152,6 +152,9 @@ namespace detail \ #elif RTTR_COMPILER == RTTR_COMPILER_GNUC // sizeof("const char* rttr::detail::f() [with T = "), sizeof("]") RTTR_REGISTRATION_FUNC_EXTRACT_VARIABLES(40, 1) +#elif RTTR_COMPILER == RTTR_COMPILER_CLANG + // sizeof("const char* rttr::detail::f() [T = "), sizeof("]") + RTTR_REGISTRATION_FUNC_EXTRACT_VARIABLES(35, 1) #else # error "This compiler does not supported extracting a function signature via preprocessor!" #endif @@ -180,6 +183,10 @@ RTTR_INLINE static const char* f() __FUNCSIG__ #elif RTTR_COMPILER == RTTR_COMPILER_GNUC __PRETTY_FUNCTION__ + #elif RTTR_COMPILER == RTTR_COMPILER_CLANG + __PRETTY_FUNCTION__ + #else + #error "Don't know how the extract type signatur for this compiler! Abort! Abort!" #endif ); } diff --git a/src/rttr/parameter_info.h b/src/rttr/parameter_info.h index 5c7f4fa2..ac4cd087 100644 --- a/src/rttr/parameter_info.h +++ b/src/rttr/parameter_info.h @@ -46,11 +46,10 @@ namespace detail template struct parameter_infos; template - std::vector convert_to_parameter_info_list(const parameter_infos&); - + static std::vector convert_to_parameter_info_list(const parameter_infos&); template - parameter_info create_param_info(const T&); + static parameter_info create_param_info(const T&); } /*! @@ -170,9 +169,7 @@ class RTTR_API parameter_info template friend parameter_info detail::create_param_info(const T&); - //template - //friend std::vector detail::convert_to_parameter_info_list(const T&); - //! Constructs a property from a property_wrapper_base. + parameter_info(const detail::parameter_info_wrapper_base* wrapper = nullptr); private: const detail::parameter_info_wrapper_base* m_wrapper; diff --git a/src/rttr/variant.cpp b/src/rttr/variant.cpp index 590b1d29..d4646f8c 100644 --- a/src/rttr/variant.cpp +++ b/src/rttr/variant.cpp @@ -238,79 +238,79 @@ bool variant::convert(const type& target_type, variant& target_var) const if (target_type == type::get()) { bool value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { char value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { int8_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { int16_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { int32_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { int64_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { uint8_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { uint16_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { uint32_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { uint64_t value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { float value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == type::get()) { double value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = value; } else if (target_type == string_type) { std::string value; - if (ok = try_basic_type_conversion(value)) + if ((ok = try_basic_type_conversion(value))) target_var = std::move(value); } } diff --git a/src/unit_tests/misc/test_misc.cpp b/src/unit_tests/misc/test_misc.cpp index 9f9bd92a..dd62dece 100644 --- a/src/unit_tests/misc/test_misc.cpp +++ b/src/unit_tests/misc/test_misc.cpp @@ -44,6 +44,7 @@ namespace { struct custom_type { + custom_type(){} int value = 23; int my_func() { return value; } diff --git a/src/unit_tests/variant/variant_ctor_test.cpp b/src/unit_tests/variant/variant_ctor_test.cpp index a4d664f6..d90a161a 100644 --- a/src/unit_tests/variant/variant_ctor_test.cpp +++ b/src/unit_tests/variant/variant_ctor_test.cpp @@ -238,7 +238,7 @@ TEST_CASE("copy non trivial type", "[variant]") { static_assert(std::is_nothrow_move_constructible::value, ""); -#if RTTR_COMPILER == RTTR_COMPILER_GNUC && RTTR_COMP_VER <= 5000 +#if __GNUG__ && __GNUC__ < 5 static_assert(!std::has_trivial_copy_constructor::value, ""); #else static_assert(!std::is_trivially_copyable::value, "");