考虑这个例子,来自bug 80985:
template <class Func>
void call(Func f)
{
f();
}
void func() noexcept { }
int main()
{
call(func);
}
如果启用了所有警告来编译这段代码,就像你所做的那样,则会产生以下结果:
$ g++ -std=c++14 -Wall foo.cxx
foo.cxx:2:6: warning: mangled name for ‘void call(Func) [with Func = void (*)() noexcept]’ will change in C++17 because the exception specification is part of a function type [-Wnoexcept-type]
void call(Func f)
^~~~
我应该如何处理这个警告?应该怎么修复?
call
完全是项目内部使用,那就没关系了。只有在两个不同的翻译单元使用它时才会有影响,其中一个是使用C++17编译的,而另一个不是。即使如此,由于call
是一个模板函数,它可能不会产生太大的影响,除了在最终可执行文件中有一个额外的定义。 - Daniel H-Wall
。如果你使用-Werror
编译或试图避免编译器错误(这是个好主意),那么你会遇到问题。根据情况,也许最好的解决方法是添加-Wno-noexcept-type
。 - Daniel H