2

我通常将警告视为错误来构建。我正在使用 Boost C++ 1.54.0 和 MinGW 4.8.1,特别是我正在使用 ptree。

#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

这个简单的程序会导致以下错误:

typedef 'cons_element' locally defined but not used [-Wunused-local-typedefs] line 228, external location: \boost\tuple\detail\tuple_basic.hpp  
typedef 'Str' locally defined but not used [-Wunused-local-typedefs] line 38, external location: \boost\property_tree\detail\xml_parser_write.hpp
typedef 'Str' locally defined but not used [-Wunused-local-typedefs] line 72, external location: \boost\property_tree\detail\xml_parser_write.hpp
typedef 'T_must_be_placeholder' locally defined but not used [-Wunused-local-typedefs]      line 37, external location: \boost\bind\arg.hpp

是一种忽略此警告的方法吗?

4

1 回答 1

8

自 4.6 起 gcc 允许忽略特定警告

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
...
...
#pragma GCC diagnostic pop

仍然有一些警告不能以这种方式关闭,但它适用于大多数人

或者像其他提到的那样做,并将 -Wno-unused-local-typedefs 添加到命令行

于 2013-07-06T11:23:49.050 回答