启用彻底和详细的 g++ 警告的标志 [英] Flags to enable thorough and verbose g++ warnings

查看:43
本文介绍了启用彻底和详细的 g++ 警告的标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常在gcc下的C语言中,我将从以下一组警告标志开始(痛苦地从多个来源组装):

Often in C under gcc, I will start with the following set of warning flags (painfully assembled from multiple sources):

-Wall -Wextra -Wformat-nonliteral -Wcast-align -Wpointer-arith -Wbad-function-cast 
-Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Winline -Wundef 
-Wnested-externs -Wcast-qual -Wshadow -Wwrite-strings -Wno-unused-parameter 
-Wfloat-equal -pedantic -ansi

我将使用这组警告构建(至少是我的调试版本)并修复我可能修复的所有内容(通常是所有内容),然后仅在标记不相关或不可修复(几乎从未如此)时删除它们.有时,如果我在编译时不得不离开,我也会添加 -Werror.

I will build (at least my debug versions) with this set of warnings and fix everything I possibly can (usually everything), and then only remove flags if they are either not relevant or not fixable (almost never the case). Sometimes, I'll also add -Werror if I have to step away while compiling.

我刚刚开始学习 C++(是的,我落后于时代 15 年),我想从正确的角度开始.

I'm just picking up C++ (yes, I'm 15 years behind the times), and I'd like to start off on the right foot.

我的问题是:是否有人在 g++ 下为 C++ 预编译了类似的完整警告标志集?(我知道其中很多都是一样的.)

My question is: Does someone have a precompiled similar set of complete warning flags for C++ under g++? (I know many of them will be the same.)

推荐答案

D'oh,我所有的原始搜索都出现了 99% 的关于如何抑制警告的帖子(够吓人的),但是我刚刚遇到了这条评论,里面有这个可爱的一组标志(一些不太相关):

D'oh, all of my original searches turned up 99% of posts on how to suppress warnings (scarily enough), but I just ran across this comment, which has this lovely set of flags (some less relevant):

交叉检查:

http://gcc.gnu.org/onlinedocs/gcc/Warning-选项.html

-g -O -Wall -Weffc++ -pedantic  
-pedantic-errors -Wextra -Waggregate-return -Wcast-align 
-Wcast-qual -Wconversion 
-Wdisabled-optimization 
-Werror -Wfloat-equal -Wformat=2 
-Wformat-nonliteral -Wformat-security  
-Wformat-y2k 
-Wimplicit  -Wimport  -Winit-self  -Winline 
-Winvalid-pch   
-Wlong-long 
-Wmissing-field-initializers -Wmissing-format-attribute   
-Wmissing-include-dirs -Wmissing-noreturn 
-Wpacked  -Wpadded -Wpointer-arith 
-Wredundant-decls 
-Wshadow -Wstack-protector 
-Wstrict-aliasing=2 -Wswitch-default 
-Wswitch-enum 
-Wunreachable-code -Wunused 
-Wunused-parameter 
-Wvariadic-macros 
-Wwrite-strings

所以,我认为这是一个很好的起点.没有意识到这是一个骗局,但至少它被深深地掩埋了.:-)

So, I think that's a good starting point. Didn't realize this was a dupe, but at least it was deeply buried. :-)

这篇关于启用彻底和详细的 g++ 警告的标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆