[Boost-bugs] [Boost C++ Libraries] #8743: warning in BOOST_BIMAP_STATIC_ERROR with clang trunk

Subject: [Boost-bugs] [Boost C++ Libraries] #8743: warning in BOOST_BIMAP_STATIC_ERROR with clang trunk
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-28 08:12:32


#8743: warning in BOOST_BIMAP_STATIC_ERROR with clang trunk
-------------------------------------+---------------------
 Reporter: nathanridge | Owner: matias
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: bimap
  Version: Boost Development Trunk | Severity: Problem
 Keywords: warning |
-------------------------------------+---------------------
 The following code:

 {{{
 #include <boost/bimap/detail/debug/static_error.hpp>

 template <typename T>
 struct S
 {
     BOOST_BIMAP_STATIC_ERROR(SOME_MESSAGE, (T));
 };
 }}}

 produces a warning with clang trunk:

 {{{
 test.cpp:6:5: warning: class member cannot be redeclared [-Wgnu]
     BOOST_BIMAP_STATIC_ERROR(SOME_MESSAGE, (T));
     ^
 boost/bimap/detail/debug/static_error.hpp:30:30: note: expanded from macro
 'BOOST_BIMAP_STATIC_ERROR'
                              BOOST_PP_CAT(BIMAP_STATIC_ERROR__,MESSAGE),
 \
                              ^
 boost/preprocessor/cat.hpp:22:32: note: expanded from macro 'BOOST_PP_CAT'
 # define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
                                ^
 boost/preprocessor/cat.hpp:29:34: note: expanded from macro
 'BOOST_PP_CAT_I'
 # define BOOST_PP_CAT_I(a, b) a ## b
                                  ^
 <scratch space>:167:1: note: expanded from here
 BIMAP_STATIC_ERROR__SOME_MESSAGE
 ^
 boost/mpl/assert.hpp:435:59: note: expanded from macro
 'BOOST_MPL_ASSERT_MSG'
 BOOST_MPL_ASSERT_MSG_IMPL( BOOST_MPL_AUX_PP_COUNTER(), c, msg, types_ ) \
                                                           ^
 boost/mpl/assert.hpp:419:8: note: expanded from macro '\
 BOOST_MPL_ASSERT_MSG_IMPL'
 struct msg; \
        ^
 test.cpp:6:5: note: previous declaration is here
 boost/bimap/detail/debug/static_error.hpp:28:16: note: expanded from macro
 'BOOST_BIMAP_STATIC_ERROR'
         struct BOOST_PP_CAT(BIMAP_STATIC_ERROR__,MESSAGE) {};
 \
                ^
 boost/preprocessor/cat.hpp:22:32: note: expanded from macro 'BOOST_PP_CAT'
 # define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
                                ^
 boost/preprocessor/cat.hpp:29:34: note: expanded from macro
 'BOOST_PP_CAT_I'
 # define BOOST_PP_CAT_I(a, b) a ## b
                                  ^
 <scratch space>:166:1: note: expanded from here
 BIMAP_STATIC_ERROR__SOME_MESSAGE
 ^
 }}}

 The reason is that the macro expands to the following:

 {{{
 template <typename T>
 struct S
 {
     struct BIMAP_STATIC_ERROR__SOME_MESSAGE {};
     struct BIMAP_STATIC_ERROR__SOME_MESSAGE;
     // <snip rest of expansion>
 };
 }}}

 The nested structure 'BIMAP_STATIC_ERROR_SOME_MESSAGE' is defined, and
 then redeclared. Such redeclaration is, apparently, not allowed. GCC
 accepts it as an extension, but the trunk version of clang warns about it.

 As a result, any code that uses Bimap is littered with warnings of this
 sort (since the library uses BOOST_BIMAP_STATIC_ERROR in multiple places).

 The fix is simple: modify BOOST_BIMAP_STATIC_ERROR to omit the definition,
 which is not necessary. The declaration emitted by BOOST_MPL_ASSERT_MSG is
 sufficient.

 Patch attached.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8743>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC