Skip to content

Commit 2bca46c

Browse files
committed
Fixed compiler warning/errors when compiling with 'clang'
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.
1 parent b2b3466 commit 2bca46c

File tree

11 files changed

+74
-38
lines changed

11 files changed

+74
-38
lines changed

3rd_party/nonius/html_group_reporter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ namespace nonius {
258258
void print_outliers(outlier_classification o) {
259259
std::cout << "found " << o.total() << " outliers among " << o.samples_seen << " samples (" << detail::percentage_ratio(o.total(), o.samples_seen) << ")\n";
260260
if(verbose) {
261-
std::cout << "low severe", o.low_severe, o.samples_seen;
262-
std::cout << "low mild", o.low_mild, o.samples_seen;
263-
std::cout << "high mild", o.high_mild, o.samples_seen;
264-
std::cout << "high severe", o.high_severe, o.samples_seen;
261+
std::cout << "low severe" << o.low_severe << " " << o.samples_seen;
262+
std::cout << "low mild" << o.low_mild << " " << o.samples_seen;
263+
std::cout << "high mild" << o.high_mild << " " << o.samples_seen;
264+
std::cout << "high severe" << o.high_severe << " " << o.samples_seen;
265265
}
266266
}
267267
void print_statistic_estimate(const char* name, estimate<fp_seconds> estimate) {

CMake/config.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
8989
endif()
9090
endif()
9191

92+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
93+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
94+
message(STATUS "added flag -std=c++11 to g++")
95+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
96+
message(WARNING "clang support is currently experimental")
97+
endif()
98+
9299

93100

94101
# RelWithDepInfo should have the same option like the Release build
@@ -99,6 +106,9 @@ if(MSVC)
99106
elseif(CMAKE_COMPILER_IS_GNUCXX )
100107
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
101108
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g")
109+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
110+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE}")
111+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g")
102112
else()
103113
message(WARNING "Please adjust CMAKE_CXX_FLAGS_RELWITHDEBINFO flags for this compiler!")
104114
endif()

CMake/utility.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,13 @@ macro(enable_rtti _ENABLE)
415415
set(enable_rtti_opt "/GR")
416416
set(disable_rtti_opt "/GR-")
417417
elseif(CMAKE_COMPILER_IS_GNUCXX )
418+
set(enable_rtti_opt "-frtti")
418419
set(disable_rtti_opt "-fno-rtti")
420+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
421+
set(enable_rtti_opt "-frtti")
422+
set(disable_rtti_opt "-fno-rtti")
423+
else()
424+
message(FATAL_ERROR "Don't know how to enable/disable RTTI for this compiler.")
419425
endif()
420426

421427
if (${_ENABLE})
@@ -452,6 +458,8 @@ function(getCompilerName _COMPILER_NAME)
452458
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${GCC_VERSION_OUTPUT}")
453459
set(COMPILER_NAME ${COMPILER_NAME}${GCC_VERSION})
454460
endif()
461+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
462+
set(COMPILER_NAME "clang")
455463
else()
456464
message(WARNING "Can not retrieve compiler name!")
457465
return()

src/benchmarks/bench_method/bench_find_method.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ nonius::benchmark bench_rttr_find_method_level_1()
6868
rttr::method m = rttr::type::get(nullptr).get_method("");
6969
meter.measure([&]()
7070
{
71-
if (m = rttr::type::get(obj_base).get_method("method_1"))
71+
if ((m = rttr::type::get(obj_base).get_method("method_1")))
7272
{
7373
value = 1;
7474
}
@@ -110,7 +110,7 @@ nonius::benchmark bench_rttr_find_method_level_3()
110110
rttr::method m = rttr::type::get(nullptr).get_method("");
111111
meter.measure([&]()
112112
{
113-
if (m = rttr::type::get(obj_base).get_method("method_3"))
113+
if ((m = rttr::type::get(obj_base).get_method("method_3")))
114114
{
115115
value = 1;
116116
}
@@ -152,7 +152,7 @@ nonius::benchmark bench_rttr_find_method_level_6()
152152
rttr::method m = rttr::type::get(nullptr).get_method("");
153153
meter.measure([&]()
154154
{
155-
if (m = rttr::type::get(obj_base).get_method("method_6"))
155+
if ((m = rttr::type::get(obj_base).get_method("method_6")))
156156
{
157157
value = 1;
158158
}
@@ -196,7 +196,7 @@ nonius::benchmark bench_rttr_find_method_neg_level_1()
196196
rttr::method m = rttr::type::get(nullptr).get_method("");
197197
meter.measure([&]()
198198
{
199-
if (m = rttr::type::get(obj_base).get_method("method_2"))
199+
if ((m = rttr::type::get(obj_base).get_method("method_2")))
200200
{
201201
value = 1;
202202
}
@@ -238,7 +238,7 @@ nonius::benchmark bench_rttr_find_method_neg_level_3()
238238
rttr::method m = rttr::type::get(nullptr).get_method("");
239239
meter.measure([&]()
240240
{
241-
if (m = rttr::type::get(obj_base).get_method("method_4"))
241+
if ((m = rttr::type::get(obj_base).get_method("method_4")))
242242
{
243243
value = 1;
244244
}
@@ -281,7 +281,7 @@ nonius::benchmark bench_rttr_find_method_neg_level_6()
281281
rttr::method m = rttr::type::get(nullptr).get_method("");
282282
meter.measure([&]()
283283
{
284-
if (m = rttr::type::get(obj_base).get_method("method_7"))
284+
if ((m = rttr::type::get(obj_base).get_method("method_7")))
285285
{
286286
value = 1;
287287
}
@@ -324,7 +324,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_level_1()
324324
rttr::method m = rttr::type::get(nullptr).get_method("");
325325
meter.measure([&]()
326326
{
327-
if (m = rttr::type::get(obj_base).get_method("method_13")) //method 13 is contained in 'class_multiple_1C'
327+
if ((m = rttr::type::get(obj_base).get_method("method_13"))) //method 13 is contained in 'class_multiple_1C'
328328
{
329329
value = 1;
330330
}
@@ -366,7 +366,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_level_3()
366366
rttr::method m = rttr::type::get(nullptr).get_method("");
367367
meter.measure([&]()
368368
{
369-
if (m = rttr::type::get(obj_base).get_method("method_15")) //method 15 is contained in 'class_multiple_3C'
369+
if ((m = rttr::type::get(obj_base).get_method("method_15"))) //method 15 is contained in 'class_multiple_3C'
370370
{
371371
value = 1;
372372
}
@@ -408,7 +408,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_level_6()
408408
rttr::method m = rttr::type::get(nullptr).get_method("");
409409
meter.measure([&]()
410410
{
411-
if (m = rttr::type::get(obj_base).get_method("method_18")) //method 18 is contained in 'class_multiple_final'
411+
if ((m = rttr::type::get(obj_base).get_method("method_18"))) //method 18 is contained in 'class_multiple_final'
412412
{
413413
value = 1;
414414
}
@@ -452,7 +452,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_neg_level_1()
452452
rttr::method m = rttr::type::get(nullptr).get_method("");
453453
meter.measure([&]()
454454
{
455-
if (m = rttr::type::get(obj_base).get_method("method_13")) //method 13 is contained in 'class_multiple_1C'
455+
if ((m = rttr::type::get(obj_base).get_method("method_13"))) //method 13 is contained in 'class_multiple_1C'
456456
{
457457
value = 1;
458458
}
@@ -494,7 +494,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_neg_level_3()
494494
rttr::method m = rttr::type::get(nullptr).get_method("");
495495
meter.measure([&]()
496496
{
497-
if (m = rttr::type::get(obj_base).get_method("method_15")) //method 15 is contained in 'class_multiple_3C'
497+
if ((m = rttr::type::get(obj_base).get_method("method_15"))) //method 15 is contained in 'class_multiple_3C'
498498
{
499499
value = 1;
500500
}
@@ -536,7 +536,7 @@ nonius::benchmark bench_rttr_find_method_cross_cast_neg_level_6()
536536
rttr::method m = rttr::type::get(nullptr).get_method("");
537537
meter.measure([&]()
538538
{
539-
if (m = rttr::type::get(obj_base).get_method("method_19")) //method 19 is contained in 'class_multiple_final_D'
539+
if ((m = rttr::type::get(obj_base).get_method("method_19"))) //method 19 is contained in 'class_multiple_final_D'
540540
{
541541
value = 1;
542542
}

src/rttr/detail/base/core_prerequisites.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace rttr
3838

3939
#define RTTR_COMPILER_MSVC 1
4040
#define RTTR_COMPILER_GNUC 2
41+
#define RTTR_COMPILER_CLANG 3
4142

4243
#define RTTR_ENDIAN_LITTLE 1
4344
#define RTTR_ENDIAN_BIG 2
@@ -57,7 +58,12 @@ namespace rttr
5758
/////////////////////////////////////////////////////////////////////////////////////////
5859
// Compiler
5960
/////////////////////////////////////////////////////////////////////////////////////////
60-
#if defined( __GNUC__ )
61+
#if defined( __clang__ )
62+
# define RTTR_COMPILER RTTR_COMPILER_CLANG
63+
# define RTTR_COMP_VER (((__clang_major__)*100) + \
64+
(__clang_minor__*10) + \
65+
__clang_patchlevel__)
66+
#elif defined( __GNUC__ )
6167
# define RTTR_COMPILER RTTR_COMPILER_GNUC
6268
# define RTTR_COMP_VER (((__GNUC__)*1000) + \
6369
(__GNUC_MINOR__*100) + \
@@ -86,6 +92,9 @@ namespace rttr
8692
#elif RTTR_COMPILER == RTTR_COMPILER_GNUC
8793
# define RTTR_INLINE inline
8894
# define RTTR_FORCE_INLINE inline __attribute__((always_inline))
95+
#elif RTTR_COMPILER == RTTR_COMPILER_CLANG
96+
# define RTTR_INLINE inline
97+
# define RTTR_FORCE_INLINE inline __attribute__((always_inline))
8998
#else
9099
# define RTTR_INLINE inline
91100
# define RTTR_FORCE_INLINE inline // no force inline for other platforms possible
@@ -108,6 +117,10 @@ namespace rttr
108117
# define RTTR_HELPER_DLL_EXPORT
109118
# define RTTR_HELPER_DLL_LOCAL
110119
# endif
120+
#elif RTTR_COMPILER == RTTR_COMPILER_CLANG
121+
# define RTTR_HELPER_DLL_IMPORT __attribute__ ((visibility ("default")))
122+
# define RTTR_HELPER_DLL_EXPORT __attribute__ ((visibility ("default")))
123+
# define RTTR_HELPER_DLL_LOCAL __attribute__ ((visibility ("hidden")))
111124
#else
112125
# error "Do not know how to export classes for this platform"
113126
#endif

src/rttr/detail/conversion/number_conversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typename std::enable_if<is_integer<F, T>::value &&
6363
bool>::type
6464
convert_to(const F& from, T& to)
6565
{
66-
if (from < 0 || (sizeof(T) < sizeof(F)) && (from > static_cast<F>(std::numeric_limits<T>::max())))
66+
if ((from < 0) || ((sizeof(T) < sizeof(F)) && (from > static_cast<F>(std::numeric_limits<T>::max()))))
6767
return false; // value too large
6868
else if (static_cast<T>(from) > std::numeric_limits<T>::max())
6969
return false; // value too large

src/rttr/detail/type/type_impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ namespace detail \
152152
#elif RTTR_COMPILER == RTTR_COMPILER_GNUC
153153
// sizeof("const char* rttr::detail::f() [with T = "), sizeof("]")
154154
RTTR_REGISTRATION_FUNC_EXTRACT_VARIABLES(40, 1)
155+
#elif RTTR_COMPILER == RTTR_COMPILER_CLANG
156+
// sizeof("const char* rttr::detail::f() [T = "), sizeof("]")
157+
RTTR_REGISTRATION_FUNC_EXTRACT_VARIABLES(35, 1)
155158
#else
156159
# error "This compiler does not supported extracting a function signature via preprocessor!"
157160
#endif
@@ -180,6 +183,10 @@ RTTR_INLINE static const char* f()
180183
__FUNCSIG__
181184
#elif RTTR_COMPILER == RTTR_COMPILER_GNUC
182185
__PRETTY_FUNCTION__
186+
#elif RTTR_COMPILER == RTTR_COMPILER_CLANG
187+
__PRETTY_FUNCTION__
188+
#else
189+
#error "Don't know how the extract type signatur for this compiler! Abort! Abort!"
183190
#endif
184191
);
185192
}

src/rttr/parameter_info.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ namespace detail
4646
template<typename...T>
4747
struct parameter_infos;
4848
template<typename...T>
49-
std::vector<parameter_info> convert_to_parameter_info_list(const parameter_infos<T...>&);
50-
49+
static std::vector<parameter_info> convert_to_parameter_info_list(const parameter_infos<T...>&);
5150

5251
template<typename T>
53-
parameter_info create_param_info(const T&);
52+
static parameter_info create_param_info(const T&);
5453
}
5554

5655
/*!
@@ -170,9 +169,7 @@ class RTTR_API parameter_info
170169

171170
template<typename T>
172171
friend parameter_info detail::create_param_info(const T&);
173-
//template<typename T>
174-
//friend std::vector<parameter_info> detail::convert_to_parameter_info_list(const T&);
175-
//! Constructs a property from a property_wrapper_base.
172+
176173
parameter_info(const detail::parameter_info_wrapper_base* wrapper = nullptr);
177174
private:
178175
const detail::parameter_info_wrapper_base* m_wrapper;

src/rttr/variant.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,79 +238,79 @@ bool variant::convert(const type& target_type, variant& target_var) const
238238
if (target_type == type::get<bool>())
239239
{
240240
bool value;
241-
if (ok = try_basic_type_conversion(value))
241+
if ((ok = try_basic_type_conversion(value)))
242242
target_var = value;
243243
}
244244
else if (target_type == type::get<char>())
245245
{
246246
char value;
247-
if (ok = try_basic_type_conversion(value))
247+
if ((ok = try_basic_type_conversion(value)))
248248
target_var = value;
249249
}
250250
else if (target_type == type::get<int8_t>())
251251
{
252252
int8_t value;
253-
if (ok = try_basic_type_conversion(value))
253+
if ((ok = try_basic_type_conversion(value)))
254254
target_var = value;
255255
}
256256
else if (target_type == type::get<int16_t>())
257257
{
258258
int16_t value;
259-
if (ok = try_basic_type_conversion(value))
259+
if ((ok = try_basic_type_conversion(value)))
260260
target_var = value;
261261
}
262262
else if (target_type == type::get<int32_t>())
263263
{
264264
int32_t value;
265-
if (ok = try_basic_type_conversion(value))
265+
if ((ok = try_basic_type_conversion(value)))
266266
target_var = value;
267267
}
268268
else if (target_type == type::get<int64_t>())
269269
{
270270
int64_t value;
271-
if (ok = try_basic_type_conversion(value))
271+
if ((ok = try_basic_type_conversion(value)))
272272
target_var = value;
273273
}
274274
else if (target_type == type::get<uint8_t>())
275275
{
276276
uint8_t value;
277-
if (ok = try_basic_type_conversion(value))
277+
if ((ok = try_basic_type_conversion(value)))
278278
target_var = value;
279279
}
280280
else if (target_type == type::get<uint16_t>())
281281
{
282282
uint16_t value;
283-
if (ok = try_basic_type_conversion(value))
283+
if ((ok = try_basic_type_conversion(value)))
284284
target_var = value;
285285
}
286286
else if (target_type == type::get<uint32_t>())
287287
{
288288
uint32_t value;
289-
if (ok = try_basic_type_conversion(value))
289+
if ((ok = try_basic_type_conversion(value)))
290290
target_var = value;
291291
}
292292
else if (target_type == type::get<uint64_t>())
293293
{
294294
uint64_t value;
295-
if (ok = try_basic_type_conversion(value))
295+
if ((ok = try_basic_type_conversion(value)))
296296
target_var = value;
297297
}
298298
else if (target_type == type::get<float>())
299299
{
300300
float value;
301-
if (ok = try_basic_type_conversion(value))
301+
if ((ok = try_basic_type_conversion(value)))
302302
target_var = value;
303303
}
304304
else if (target_type == type::get<double>())
305305
{
306306
double value;
307-
if (ok = try_basic_type_conversion(value))
307+
if ((ok = try_basic_type_conversion(value)))
308308
target_var = value;
309309
}
310310
else if (target_type == string_type)
311311
{
312312
std::string value;
313-
if (ok = try_basic_type_conversion(value))
313+
if ((ok = try_basic_type_conversion(value)))
314314
target_var = std::move(value);
315315
}
316316
}

src/unit_tests/misc/test_misc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace
4444
{
4545
struct custom_type
4646
{
47+
custom_type(){}
4748
int value = 23;
4849

4950
int my_func() { return value; }

0 commit comments

Comments
 (0)