GCC 在 Boost Source 中的警告

HCS*_*CSF 6 c++ boost

我正在使用 boost 1.63,当我编译包含#include <boost/algorithm/string.hpp>.

海湾合作委员会抱怨:

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>::************
                     ^
Run Code Online (Sandbox Code Playgroud)

我查看了来源,抱怨部分是:

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 )
    );
Run Code Online (Sandbox Code Playgroud)

问题:

  • 什么是failed ************ (Pred::************?语法对我来说看起来很奇怪。
  • 如何在不抑制所有类似警告的情况下修复它?由于 GCC 的警告通常有效且有助于检测问题。

我在网上搜索,最接近的,相关的是这个。但它的解决方案似乎只是抑制了警告。

谢谢!

Nik*_* C. 6

通常 GCC 和 Clang 会自动抑制来自/usr. 然而,似乎/opt并没有。要告诉编译器应该将 boost 头文件视为系统头文件,请使用-isystem而不是-I将 boost 头文件添加到包含路径中。