Skip to content

Commit

Permalink
Fixed compiler warning/errors when compiling with 'clang'
Browse files Browse the repository at this point in the history
However, the unit tests still fail, because of the clang result of __PRETTY_FUNCTION__
(the pointer symbol '*' will be placed after a whitespace of the type)
To fix this correctly, it will take more time.
  • Loading branch information
acki-m committed Dec 23, 2015
1 parent b2b3466 commit 2bca46c
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 38 deletions.
8 changes: 4 additions & 4 deletions 3rd_party/nonius/html_group_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<fp_seconds> estimate) {
Expand Down
10 changes: 10 additions & 0 deletions CMake/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions CMake/utility.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 12 additions & 12 deletions src/benchmarks/bench_method/bench_find_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion src/rttr/detail/base/core_prerequisites.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) + \
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/rttr/detail/conversion/number_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typename std::enable_if<is_integer<F, T>::value &&
bool>::type
convert_to(const F& from, T& to)
{
if (from < 0 || (sizeof(T) < sizeof(F)) && (from > static_cast<F>(std::numeric_limits<T>::max())))
if ((from < 0) || ((sizeof(T) < sizeof(F)) && (from > static_cast<F>(std::numeric_limits<T>::max()))))
return false; // value too large
else if (static_cast<T>(from) > std::numeric_limits<T>::max())
return false; // value too large
Expand Down
7 changes: 7 additions & 0 deletions src/rttr/detail/type/type_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}
Expand Down
9 changes: 3 additions & 6 deletions src/rttr/parameter_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ namespace detail
template<typename...T>
struct parameter_infos;
template<typename...T>
std::vector<parameter_info> convert_to_parameter_info_list(const parameter_infos<T...>&);

static std::vector<parameter_info> convert_to_parameter_info_list(const parameter_infos<T...>&);

template<typename T>
parameter_info create_param_info(const T&);
static parameter_info create_param_info(const T&);
}

/*!
Expand Down Expand Up @@ -170,9 +169,7 @@ class RTTR_API parameter_info

template<typename T>
friend parameter_info detail::create_param_info(const T&);
//template<typename T>
//friend std::vector<parameter_info> 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;
Expand Down
26 changes: 13 additions & 13 deletions src/rttr/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,79 +238,79 @@ bool variant::convert(const type& target_type, variant& target_var) const
if (target_type == type::get<bool>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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>())
{
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);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/unit_tests/misc/test_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace
{
struct custom_type
{
custom_type(){}
int value = 23;

int my_func() { return value; }
Expand Down
2 changes: 1 addition & 1 deletion src/unit_tests/variant/variant_ctor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ TEST_CASE("copy non trivial type", "[variant]")
{
static_assert(std::is_nothrow_move_constructible<self_aware>::value, "");

#if RTTR_COMPILER == RTTR_COMPILER_GNUC && RTTR_COMP_VER <= 5000
#if __GNUG__ && __GNUC__ < 5
static_assert(!std::has_trivial_copy_constructor<self_aware>::value, "");
#else
static_assert(!std::is_trivially_copyable<self_aware>::value, "");
Expand Down

0 comments on commit 2bca46c

Please sign in to comment.