Fix: remove type constness in URCU_FORCE_CAST's C++ version
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Aug 2022 17:11:21 +0000 (13:11 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Aug 2022 17:37:32 +0000 (13:37 -0400)
commit06326a94ac233064654c7100b6384b2833f7b898
treebc356a84ec7475a2c2b2f859a5d407cb369eed16
parent2ad3cfebe9d73f2a1f7f2b9a5c013a9759f14f73
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<type>(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<const int>(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 <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/urcu/compiler.h
This page took 0.025022 seconds and 4 git commands to generate.