C++:什么 GNU G++ 参数?

2022-01-23 00:00:00 gcc warnings g++ c++

可能重复:
C/C++ 编译器的最佳编译器警告级别?

GCC 有数以千计的选项来添加更多警告;我希望 -Wall -Wextra -pedantic 包含所有有用的,但现在我遇到了 -Woverloaded-virtual 这对我来说真的很好.

GCC has thousands of options to add more warnings; I was hoping that -Wall -Wextra -pedantic included all the useful ones, but just now I met -Woverloaded-virtual which seems really nice to me.

您还使用或推荐哪些其他 G++ 参数?

What other G++ parameters do you use or would you recommend?

推荐答案

不是完全相同的类别,但我总是用 -Werror 编译以将警告标记为错误.很有用.

Not quite the same category but I always compile with -Werror to flag warnings as errors. Very useful.

为了使这项工作与第 3 方标头一起使用,我通过 -isystem 而不是 -I 包含这些标头……否则这些标头中的警告会破坏构建.

To make this work with 3rd party headers, I include those headers via -isystem instead of -I …?otherwise warnings in those headers will break the build.

还有 -Weffc++ 会针对 Meyers 的 Effective C++ 中概述的特定问题发出警告.但是,我发现这太苛刻了.例如,它会针对未声明虚拟析构函数的基类发出警告.理论上,这很好,但我正在开发一个模板库,它使用继承来重用代码(和策略类),显然它们没有(也不需要)虚拟析构函数.

There’s also -Weffc++ which warns for specific issues outlined in Meyers’ Effective C++. However, I’ve found this too harsh. For example, it warns for base classes that don’t declare virtual destructors. In theory, this is very nice but I’m working on a template library that uses inheritance for code reuse (and policy classes) and obviously they don’t have (nor need) virtual destructors.

相关文章