序言:我知道,禁用警告不是一个好主意.无论如何,我对此有一个技术问题.
使用GCC 3.3.6,我收到以下警告:
choosing ... over ... because conversion sequence for the argument is better.
Run Code Online (Sandbox Code Playgroud)
现在,我想通过提供类似的参数来禁用此警告,如gcc警告选项中所述
-Wno-theNameOfTheWarning
Run Code Online (Sandbox Code Playgroud)
但我不知道警告的名称.如何找出禁用此警告的选项的名称?
我无法修复警告,因为它出现在无法更改的外部库的标头中.它在boost序列化(rx(s, count))中:
template<class Archive, class Container, class InputFunction, class R>
inline void load_collection(Archive & ar, Container &s)
{
s.clear();
// retrieve number of elements
collection_size_type count;
unsigned int item_version;
ar >> BOOST_SERIALIZATION_NVP(count);
if(3 < ar.get_library_version())
ar >> BOOST_SERIALIZATION_NVP(item_version);
else
item_version = 0;
R rx;
rx(s, count);
std::size_t c = count;
InputFunction ifunc;
while(c-- > 0){
ifunc(ar, s, item_version);
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过,#pragma GCC system_header但这没有效果.使用-isystem而不是-I也行不通.
一般的问题仍然是:我知道警告信息的内容.但我不知道与gcc警告选项的相关性.
您可以使用以下-fdiagnostics-show-option选项找出与给定警告关联的选项:
$ gcc -fdiagnostics-show-option -Wall foo.c
foo.c: In function ‘main’:
foo.c:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
Run Code Online (Sandbox Code Playgroud)
关于这个我的两分钱:假设没有办法实际修复警告,希望你可以设法禁用警告以进行少量编译,这样如果你在自己的代码中犯了类似的错误,你会被警告.
编辑:这似乎是-Wconversion.(通过在源代码中找到 - 你可以只查看一些警告文本,并找到对它的调用warning( OPT_W_conversion, ....)