Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC's Warning in Boost Source

Tags:

c++

boost

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!

like image 381
HCSF Avatar asked Aug 12 '19 08:08

HCSF


People also ask

How do I stop a GCC warning?

If the value of y is always 1, 2 or 3, then x is always initialized, but GCC doesn't know this. To suppress the warning, you need to provide a default case with assert(0) or similar code. This option also warns when a non-volatile automatic variable might be changed by a call to longjmp.

How do I enable warnings in GCC?

GCC 4.3+ now has -Q --help=warnings , and you can even specify --help=warnings,C to just print out the C related warnings.

Which option can be used to display compiler warnings?

You can use the -Werror compiler flag to turn all or some warnings into errors.

Which flags would you pass to your C++ compiler so it warns you about implicit conversions?

The C++ compiler comes with a lot of useful warnings that warn you about potential errors and issues in your code. You always want to compile with warnings. A warning flag starts with -W and then the name of the warning, for example -Wconversion which warns about implicit conversions.


1 Answers

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.

like image 61
Nikos C. Avatar answered Oct 30 '22 05:10

Nikos C.