From: Simon Marchi Date: Wed, 17 Aug 2022 17:11:21 +0000 (-0400) Subject: Fix: remove type constness in URCU_FORCE_CAST's C++ version X-Git-Tag: v0.14.0~19 X-Git-Url: http://git.lttng.org/?p=userspace-rcu.git;a=commitdiff_plain;h=06326a94ac233064654c7100b6384b2833f7b898 Fix: remove type constness in URCU_FORCE_CAST's C++ version The test added by the following patch wouldn't compile, when built without _LGPL_SOURCE: CXX test_build_dynlink_cxx-test_build_cxx.o In file included from ../../include/urcu/arch.h:25, from /home/simark/src/urcu/tests/unit/test_build.c:28, from /home/simark/src/urcu/tests/unit/test_build_cxx.cpp:3: /home/simark/src/urcu/tests/unit/test_build.c: In function ‘void test_build_rcu_dereference()’: /home/simark/src/urcu/include/urcu/compiler.h:85:42: error: type qualifiers ignored on cast result type [-Werror=ignored-qualifiers] 85 | #define URCU_FORCE_CAST(type, arg) (reinterpret_cast(arg)) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/simark/src/urcu/include/urcu/pointer.h:71:49: note: in expansion of macro ‘URCU_FORCE_CAST’ 71 | __typeof__(p) _________p1 = URCU_FORCE_CAST(__typeof__(p), \ | ^~~~~~~~~~~~~~~ /home/simark/src/urcu/tests/unit/test_build.c:133:9: note: in expansion of macro ‘rcu_dereference’ 133 | rcu_dereference(opaque_const); | ^~~~~~~~~~~~~~~ The compiler complains that we do a cast to a const type, equivalent to: reinterpret_cast(arg) ... and that the const is meaningless in this context. Use std::remove_cv to strip away any const or volatile qualifiers from the type (using a volatile type would result in the same warning). Change-Id: I94e79fcccfc2108021752f65977e1548084c646a Signed-off-by: Simon Marchi Signed-off-by: Mathieu Desnoyers --- diff --git a/include/urcu/compiler.h b/include/urcu/compiler.h index 34eb564..2f32b38 100644 --- a/include/urcu/compiler.h +++ b/include/urcu/compiler.h @@ -21,6 +21,10 @@ #include /* for offsetof */ +#if defined __cplusplus +# include /* for std::remove_cv */ +#endif + #define caa_likely(x) __builtin_expect(!!(x), 1) #define caa_unlikely(x) __builtin_expect(!!(x), 0) @@ -82,7 +86,7 @@ #define __rcu #ifdef __cplusplus -#define URCU_FORCE_CAST(type, arg) (reinterpret_cast(arg)) +#define URCU_FORCE_CAST(_type, arg) (reinterpret_cast::type>(arg)) #else #define URCU_FORCE_CAST(type, arg) ((type) (arg)) #endif