gpt4 book ai didi

c++ - 将特定的 gcc 警告变成错误

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:24 28 4
gpt4 key购买 nike

所以我知道我可以使用 -Werror=... 将警告变成错误,但我想将以下警告变成错误:

“类xxx有虚函数但非虚析构函数”

据我所知,您遇到此错误的唯一方法是打开过于讨厌的 -Weffc++ 标志。有没有一种方法(或者 -Weffc++ 中这个警告的子标志是什么)只打印这个警告然后把它变成一个错误?

谢谢!

最佳答案

-Wnon-virtual-dtor-Weffc++开启的特定警告名称。要将任何警告变成错误,您可以使用 -Werror=...。因此,如果警告是 -Wspam,则将其变成错误将是 -Werror=spam。所以在这种情况下,您将使用 -Werror=non-virtual-dtor

但是,如果您使用的是 GCC 4.8 及更高版本,我不认为此警告特别有用。然后你可以访问高级 -Wdelete-non-virtual-dtor:

Warn when delete is used to destroy an instance of a class that has virtual functions and non-virtual destructor. It is unsafe to delete an instance of a derived class through a pointer to a base class if the base class does not have a virtual destructor. This warning is enabled by -Wall.

请注意,g++ -Wspam -Werror=spamg++ -Werror=spam 相同。将警告变为错误会自动打开该警告。

在相关说明中,您不是唯一认为 -Weffc++ is a little overzealous 的人.

关于c++ - 将特定的 gcc 警告变成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10949438/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com