Opened 9 years ago
Closed 7 years ago
#8743 closed Bugs (fixed)
warning in BOOST_BIMAP_STATIC_ERROR with clang trunk
| Reported by: | Nathan Ridge | Owned by: | Matias Capeletto |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | bimap |
| Version: | Boost 1.55.0 | Severity: | Problem |
| Keywords: | warning | Cc: | braden@… |
Description
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.
Attachments (1)
Change History (10)
by , 9 years ago
| Attachment: | bimap-warning.patch added |
|---|
comment:1 by , 9 years ago
| Cc: | added |
|---|---|
| Version: | Boost Development Trunk → Boost 1.55.0 |
comment:2 by , 8 years ago
I also ran into this with the boost "master" tip for 1.56 plus the latest clang-3.5.0. If you use -Wall -Werror in your projects this becomes a build error.
follow-up: 4 comment:3 by , 8 years ago
doesn't clear the issue.. created a lot of warnings and issues
comment:4 by , 8 years ago
Replying to anonymous:
doesn't clear the issue.. created a lot of warnings and issues
Are you referring to my patch from comment 1?
comment:5 by , 8 years ago
This patch fixes using bimap on clang with option -Wall -Werror perfectly; should be applied to upstream.
comment:7 by , 7 years ago
+1, fixed my problems as well. Could one of the developers at least give some kind of a statement why this didn't get merged yet?
comment:9 by , 7 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Applied from pull-request: https://github.com/boostorg/bimap/commit/e4b46b3258f0a5be1484d9c507f6133930498925, thanks and sorry for the delay.

patch that fixes the warning