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 /home/foo/opt/1/include/boost/atomic/detail/atomic_template.hpp:25:0,
                 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*]’:
/home/foo/opt/1/include/boost/atomic/detail/atomic_template.hpp:426:139:   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*]’
/home/foo/opt/1/include/boost/atomic/detail/atomic_template.hpp:686:101:   required from ‘constexpr boost::atomics::atomic<T>::atomic(boost::atomics::atomic<T>::value_arg_type) [with T = const char*; boost::atomics::atomic<T>::value_arg_type = const char*]’
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 this:

&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.

Regards,
Isaac