Opened 11 years ago

Closed 10 years ago

#5810 closed Bugs (fixed)

BOOST_STATIC_ASSERT requires unnecessary parentheses

Reported by: tsoae@… 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 anonymous, 11 years ago

Type: Feature RequestsBugs

comment:2 by John Maddock, 10 years ago

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.

comment:3 by John Maddock, 10 years ago

Resolution: fixed
Status: newclosed

(In [82886]) Use variadic macros in static assert to make use easier. Add warning suppression for GCC. Minor doc fix. Fixes #5810. Fixes #7242. Fixes #7966.

Note: See TracTickets for help on using tickets.