Opened 11 years ago
Closed 10 years ago
#5810 closed Bugs (fixed)
BOOST_STATIC_ASSERT requires unnecessary parentheses
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | static_assert |
Version: | Boost 1.47.0 | Severity: | Cosmetic |
Keywords: | Cc: |
Description
In Boost 1.47.0 the BOOST_STATIC_ASSERT macro is defined as having one parameter. When the argument contains comma-separated template arguments, we (sometimes) have to use additional parentheses:
BOOST_STATIC_ASSERT(is_base_of<B, D>::value); /* error: two arguments passed */
BOOST_STATIC_ASSERT((is_base_of<B, D>::value)); /* OK */
Today many C++ compilers support variadic macros, so for such compilers BOOST_STATIC_ASSERT might be defined like this:
#ifndef BOOST_NO_STATIC_ASSERT
# define BOOST_STATIC_ASSERT(...) \
static_assert((VA_ARGS), #VA_ARGS)
#else
....
and BOOST_STATIC_ASSERT(is_base_of<B, D>::value) might be correct. Are there any problems with such definition?
Change History (3)
comment:1 by , 11 years ago
Type: | Feature Requests → Bugs |
---|
I'll commit a patch for this shortly, however, only a partial solution is possible for BOOST_STATIC_ASSERT_MSG(expression, message), as I can't see a way to define it in terms of BOOST_STATIC_ASSERT using variadic macros. It does work when a native static_assert is available though.