来自提升的警告

Warnings from boost

本文关键字:警告      更新时间:2023-10-16

我有很多来自提升库标头的警告,有什么办法可以解决这个问题吗?

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;

如果这很重要,我的gcc --version

gcc (Ubuntu 4.8.1-2ubuntu1~12.04) 4.8.1

更新:

这个类似问题的解决方案看起来很合理:https://stackoverflow.com/a/1900578/1179925

主要问题是来自第三方或系统头文件的(大量)警告,可以(大多数时候)安全地忽略。我的解决方案是将我的源文件命名为*.cpp*.hpp,并添加其他头文件*.cpp.h*.hpp.h,以包含警告生成头文件,如下所示:

#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

这至少应该适用于GCC和Visual Studio,因为我从未测试过Sun C++编译器。

对于Visual Studio,警告pragma可以放入"正常"头文件和源文件中,但对于GCC,这将不起作用。对于 GCC,第 pragma GCC system_header 行将整个头文件声明为系统头文件,其中警告将被忽略。当然,这不是一个系统头文件,但它应该只包括那些,其中提升头文件有点像。

当然:向解决方案中添加更多头文件远非一个优雅的解决方案。但它有效。