Boost logo

Boost Users :

Subject: [Boost-users] Warning message using Boost.Atomic char pointer with GCC 4.8
From: Isaac To (isaac.to_at_[hidden])
Date: 2016-03-15 21:18:17

Hi all,

It looks like Boost.Atomic (in Boost 1.60) uses constructs that GCC 4.8 (in
CentOS 7) really dislike. With the following simple test program...

#include <boost/atomic.hpp>
int main() {
    boost::atomic<const char*> p1("abc"), p2;
    p2 = p1.load();

What I see is:

$ g++ -std=c++11 -I ~/opt/1/include t.cpp
In file included from
                 from /home/foo/opt/1/include/boost/atomic/atomic.hpp:22,
                 from /home/foo/opt/1/include/boost/atomic.hpp:12,
                 from t.cpp:1:
/home/foo/opt/1/include/boost/atomic/detail/bitwise_cast.hpp: In
instantiation of ‘To boost::atomics::detail::bitwise_cast(const From&)
[with To = long unsigned int; From = const char*]’:
required from ‘boost::atomics::detail::base_atomic<T*,
void*>::base_atomic(T* const&) [with T = const char;
boost::atomics::detail::base_atomic<T*, void*>::value_type = const char*]’
required from ‘constexpr
[with T = const char*; boost::atomics::atomic<T>::value_arg_type = const
t.cpp:4:40: required from here
/home/foo/opt/1/include/boost/atomic/detail/bitwise_cast.hpp:45:5: warning:
casting ‘const char* const’ to ‘const char&’ does not dereference pointer
[enabled by default]

The offending code is boost/atomic/detail/bitwise_cast.hpp:45, looking like

&reinterpret_cast< const char& >(from)

Here "from" is of type From = const char*. The code needs to find the
address storing the pointer. It reinterprets the pointer as a const char
reference, where address is to be found.

In actual production code I use -Werror, so this stops the compiler from
producing an executable. Most other warnings caused by Boost can be opted
out, but apparently not this particular one.

Should this be considered too funny a use of the C++ language to be
considered a bug? For now I change the const char* to const void* with
extra reinterpret_cast's, which the compiler won't complain about.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at