9

I am using boost 1.63 and when I compile my application that includes #include <boost/algorithm/string.hpp>.

GCC complains:

In file included from /opt/boost/boost/mpl/aux_/na_assert.hpp:23,
                 from /opt/boost/boost/mpl/arg.hpp:25,
                 from /opt/boost/boost/mpl/placeholders.hpp:24,
                 from /opt/boost/boost/iterator/iterator_categories.hpp:17,
                 from /opt/boost/boost/iterator/iterator_facade.hpp:14,
                 from /opt/boost/boost/range/iterator_range_core.hpp:27,
                 from /opt/boost/boost/range/iterator_range.hpp:13,
                 from /opt/boost/boost/range/as_literal.hpp:22,
                 from /opt/boost/boost/algorithm/string/trim.hpp:19,
                 from /opt/boost/boost/algorithm/string.hpp:19,
         from [my source that includes <boost/algorithm/string.hpp>]
/opt/boost/boost/mpl/assert.hpp:188:21: warning: unnecessary parentheses in declaration of ‘assert_arg’ [-Wparentheses]
 failed ************ (Pred::************
                     ^
/opt/boost/boost/mpl/assert.hpp:193:21: warning: unnecessary parentheses in declaration of ‘assert_not_arg’ [-Wparentheses]
 failed ************ (boost::mpl::not_<Pred>::************
                     ^

I looked at the source and complained section is:

template< typename Pred >
failed ************ (Pred::************
      assert_arg( void (*)(Pred), typename assert_arg_pred<Pred>::type )
    );

template< typename Pred >
failed ************ (boost::mpl::not_<Pred>::************
      assert_not_arg( void (*)(Pred), typename assert_arg_pred_not<Pred>::type )
    );

Questions:

  • what is failed ************ (Pred::************? The syntax looks weird to me.
  • how I can fix it without suppressing all similar warnings? As GCC's warnings are usually valid and helpful in detecting issues.

I searched online, and the closest, related one is this. But its solution seems to just suppress the warnings.

Thanks!

6
  • 1
    Unnecessary parens is absolutely a warning and not any sort of error. It just means that, while the syntax is valid, the parens do not need to be there. What's your command line? Commented Aug 12, 2019 at 8:18
  • 1
    There is BOOST_MPL_IGNORE_PARENTHESES_WARNING macro (at least in recent boost) to suppress this message. failed ******** looks like a pointer declaration. Commented Aug 12, 2019 at 8:21
  • @Qix I was using cmake, and it generated something like -I/opt/boost/boost. I agree that it is a warning. But I want to turn on -Werror.
    – HCSF
    Commented Aug 12, 2019 at 8:44
  • @VTT that's an interesting solution. But I just did grep -r "BOOST_MPL_IGNORE_PARENTHESES_WARNING" . in /opt/boost where my boost lives. And it has nothing. Probably boost 1.63 doesn't have it yet.
    – HCSF
    Commented Aug 12, 2019 at 8:47
  • 3
    CMake can generate -isystem flags as per @NikosC's answer. Just use the SYSTEM argument. i.e.: target_include_directories(myapp SYSTEM PUBLIC "/opt/boost/boost") Commented Aug 12, 2019 at 8:48

1 Answer 1

8

Normally GCC and Clang automatically suppress warnings from headers in /usr. However, it seems that for /opt it doesn't. To tell the compiler that the boost headers should be treated as system headers, use -isystem instead of -I to add the boost headers to the include paths.

Not the answer you're looking for? Browse other questions tagged or ask your own question.