Warnings from boost

2019-06-08 12:41发布

问题:

I have lots of warning from boost library headers, is there any way to resolve this problem?

libs/boost/include/boost/numeric/ublas/detail/vector_assign.hpp:382:39: warning: typedef ‘reference’ locally defined but not used [-Wunused-local-typedefs]
         typedef typename V::reference reference;

libs/boost/include/boost/numeric/ublas/detail/vector_assign.hpp:516:40: warning: typedef ‘value_type’ locally defined but not used [-Wunused-local-typedefs]
         typedef typename V::value_type value_type;

libs/boost/include/boost/numeric/ublas/detail/matrix_assign.hpp:644:40: warning: typedef ‘value_type’ locally defined but not used [-Wunused-local-typedefs]
         typedef typename M::value_type value_type;

libs/boost/include/boost/numeric/ublas/operation.hpp:132:26: warning: typedef ‘expression2_type’ locally defined but not used [-Wunused-local-typedefs]
         typedef const E2 expression2_type;

libs/boost/include/boost/numeric/ublas/operation.hpp:191:26: warning: typedef ‘expression1_type’ locally defined but not used [-Wunused-local-typedefs]
         typedef const E1 expression1_type;

libs/boost/include/boost/numeric/ublas/operation.hpp:193:39: warning: typedef ‘size_type’ locally defined but not used [-Wunused-local-typedefs]
         typedef typename V::size_type size_type;

If it matters my gcc --version

gcc (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1

UPDATE:

This solution to similar problem looks resonable: https://stackoverflow.com/a/1900578/1179925

回答1:

The main problem is (lots of) warnings from 3rd party or system header files that can (most of the time) safely be ignored. My solution to this was to name my source files *.cpp and *.hpp and added additional header files *.cpp.h and *.hpp.h for including warning producing header files like this:

#pragma once

#if defined __GNUC__
#   pragma GCC system_header
#elif defined __SUNPRO_CC
#   pragma disable_warn
#elif defined _MSC_VER
//# pragma warning(push, 0)
#   pragma warning(push)
#   pragma warning(disable : 4800)
//# pragma warning(disable : ...)
#endif

// BEGIN INCLUDING 3RD PARTY HEADERS
#include <QApplication>
#include <QTextCodec>
#include <QTranslator>
#include <QLocale>
//#include <boost/someboostheader.hpp>
// END INCLUDING 3RD PARTY HEADERS

#if defined __SUNPRO_CC
#   pragma enable_warn
#elif defined _MSC_VER
#   pragma warning(pop)
#endif

This should work at least with GCC and Visual Studio since I've never tested the Sun C++ compiler.

For Visual Studio the warning pragmas could be put into the "normal" header and source files, but for GCC that won't work. With GCC the line pragma GCC system_header declares that entire header file as system header file where warnings would be ignored. Of course this is not a system header file, but it is supposed to only include those, which boost header files kind of are.

Of course: adding some more header files to your solution is far from being an elegant solution. But it works.