gccの警告オプションの調べ方

提供: C言語入門
2016年8月12日 (金) 18:56時点におけるDaemon (トーク | 投稿記録)による版 (ページの作成:「gcc コンパイラには、いろいろな警告オプションがあります。警告オプションにより、プログラムの問題を発見することがで...」)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索
スポンサーリンク

gcc コンパイラには、いろいろな警告オプションがあります。警告オプションにより、プログラムの問題を発見することができます。どのオプションが有効になっているのか、確認する方法を紹介します。

読み方

gcc
じーしーしー

概要

gcc コンパイラには、いろいろな警告オプションがあります。警告オプションにより、プログラムの問題を発見することができます。どのオプションが有効になっているのか、確認する方法を紹介します。

警告オプションをまとめて有効にする便利な -Wall や -Wextra などがありますが、それらを設定したときに、どのオプションが有効になっているのか簡単に調べることができます。

警告オプションの確認のやり方

以下のコマンドラインで、どの警告オプションが有効になっているか確認できます。

$ gcc -Q --help=warnings

以下のコマンドラインの出力を比較してみると、オプションによる違いがわかります。

$ gcc -Wall -Q --help=warnings
$ gcc -Wall -Wextra -Q --help=warnings

実行例

以下は、gcc バージョン 5.3.0 の例になります。

$ gcc5 --version
gcc5 (FreeBSD Ports Collection) 5.3.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
$ gcc5 -Q --help=warnings
The following options control compiler warning messages:
  --all-warnings              		
  --extra-warnings            		
  -W                          		
  -Wabi                       		[disabled]
  -Wabi-tag                   		[disabled]
  -Wabi=                      		
  -Waddress                   		[disabled]
  -Waggregate-return          		[disabled]
  -Waggressive-loop-optimizations 	[enabled]
  -Waliasing                  		[disabled]
  -Walign-commons             		[enabled]
  -Wall                       		
  -Wampersand                 		[disabled]
  -Warray-bounds              		[disabled]
  -Warray-bounds=             		0
  -Warray-temporaries         		[disabled]
  -Wassign-intercept          		[disabled]
  -Wattributes                		[enabled]
  -Wbad-function-cast         		[disabled]
  -Wbool-compare              		[disabled]
  -Wbuiltin-macro-redefined   		[enabled]
  -Wc++-compat                		[disabled]
  -Wc++0x-compat              		[disabled]
  -Wc++11-compat              		
  -Wc++14-compat              		[disabled]
  -Wc-binding-type            		[disabled]
  -Wc90-c99-compat            		[enabled]
  -Wc99-c11-compat            		[enabled]
  -Wcast-align                		[disabled]
  -Wcast-qual                 		[disabled]
  -Wchar-subscripts           		[disabled]
  -Wcharacter-truncation      		[disabled]
  -Wchkp                      		[disabled]
  -Wclobbered                 		[disabled]
  -Wcomment                   		[disabled]
  -Wcomments                  		
  -Wcompare-reals             		[disabled]
  -Wconditionally-supported   		[disabled]
  -Wconversion                		[disabled]
  -Wconversion-extra          		[disabled]
  -Wconversion-null           		[enabled]
  -Wcoverage-mismatch         		[enabled]
  -Wcpp                       		[enabled]
  -Wctor-dtor-privacy         		[disabled]
  -Wdate-time                 		[disabled]
  -Wdeclaration-after-statement 	[enabled]
  -Wdelete-incomplete         		[enabled]
  -Wdelete-non-virtual-dtor   		[disabled]
  -Wdeprecated                		[enabled]
  -Wdeprecated-declarations   		[enabled]
  -Wdesignated-init           		[enabled]
  -Wdisabled-optimization     		[disabled]
  -Wdiscarded-array-qualifiers 		[enabled]
  -Wdiscarded-qualifiers      		[enabled]
  -Wdiv-by-zero               		[enabled]
  -Wdouble-promotion          		[disabled]
  -Weffc++                    		[disabled]
  -Wempty-body                		[disabled]
  -Wendif-labels              		[enabled]
  -Wenum-compare              		[enabled]
  -Werror-implicit-function-declaration 	
  -Wextra                     		[disabled]
  -Wfloat-equal               		[disabled]
  -Wformat                    		
  -Wformat-contains-nul       		[disabled]
  -Wformat-extra-args         		[disabled]
  -Wformat-nonliteral         		[disabled]
  -Wformat-security           		[disabled]
  -Wformat-signedness         		[disabled]
  -Wformat-y2k                		[disabled]
  -Wformat-zero-length        		[disabled]
  -Wformat=                   		0
  -Wfree-nonheap-object       		[enabled]
  -Wfunction-elimination      		[disabled]
  -Wignored-qualifiers        		[disabled]
  -Wimplicit                  		[disabled]
  -Wimplicit-function-declaration 	[enabled]
  -Wimplicit-int              		[enabled]
  -Wimplicit-interface        		[disabled]
  -Wimplicit-procedure        		[disabled]
  -Wincompatible-pointer-types 		[enabled]
  -Winherited-variadic-ctor   		[enabled]
  -Winit-self                 		[disabled]
  -Winline                    		[disabled]
  -Wint-conversion            		[enabled]
  -Wint-to-pointer-cast       		[enabled]
  -Wintrinsic-shadow          		[disabled]
  -Wintrinsics-std            		[disabled]
  -Winvalid-memory-model      		[enabled]
  -Winvalid-offsetof          		[enabled]
  -Winvalid-pch               		[disabled]
  -Wjump-misses-init          		[disabled]
  -Wlarger-than-              		
  -Wlarger-than=<number>      		
  -Wline-truncation           		[enabled]
  -Wliteral-suffix            		[enabled]
  -Wlogical-not-parentheses   		[disabled]
  -Wlogical-op                		[disabled]
  -Wlong-long                 		[enabled]
  -Wmain                      		[enabled]
  -Wmaybe-uninitialized       		[disabled]
  -Wmemset-transposed-args    		[disabled]
  -Wmissing-braces            		[disabled]
  -Wmissing-declarations      		[disabled]
  -Wmissing-field-initializers 		[disabled]
  -Wmissing-include-dirs      		[disabled]
  -Wmissing-parameter-type    		[disabled]
  -Wmissing-prototypes        		[disabled]
  -Wmultichar                 		[disabled]
  -Wnarrowing                 		[enabled]
  -Wnested-externs            		[disabled]
  -Wnoexcept                  		[disabled]
  -Wnon-template-friend       		[enabled]
  -Wnon-virtual-dtor          		[disabled]
  -Wnonnull                   		[disabled]
  -Wnormalized=<none|id|nfc|nfkc> 	nfc
  -Wodr                       		[enabled]
  -Wold-style-cast            		[disabled]
  -Wold-style-declaration     		[disabled]
  -Wold-style-definition      		[disabled]
  -Wopenmp-simd               		[disabled]
  -Woverflow                  		[enabled]
  -Woverlength-strings        		[disabled]
  -Woverloaded-virtual        		[disabled]
  -Woverride-init             		[disabled]
  -Wpacked                    		[disabled]
  -Wpacked-bitfield-compat    		[enabled]
  -Wpadded                    		[disabled]
  -Wparentheses               		[disabled]
  -Wpedantic                  		[disabled]
  -Wpmf-conversions           		[enabled]
  -Wpointer-arith             		[disabled]
  -Wpointer-sign              		[disabled]
  -Wpointer-to-int-cast       		[enabled]
  -Wpragmas                   		[enabled]
  -Wproperty-assign-default   		[enabled]
  -Wprotocol                  		[enabled]
  -Wreal-q-constant           		[disabled]
  -Wrealloc-lhs               		[disabled]
  -Wrealloc-lhs-all           		[disabled]
  -Wredundant-decls           		[disabled]
  -Wreorder                   		[disabled]
  -Wreturn-local-addr         		[enabled]
  -Wreturn-type               		[disabled]
  -Wselector                  		[disabled]
  -Wsequence-point            		[disabled]
  -Wshadow                    		[disabled]
  -Wshadow-ivar               		[enabled]
  -Wshift-count-negative      		[enabled]
  -Wshift-count-overflow      		[enabled]
  -Wsign-compare              		[disabled]
  -Wsign-promo                		[disabled]
  -Wsized-deallocation        		[disabled]
  -Wsizeof-array-argument     		[enabled]
  -Wsizeof-pointer-memaccess  		[disabled]
  -Wstack-protector           		[disabled]
  -Wstack-usage=              		0xffffffff
  -Wstrict-aliasing           		
  -Wstrict-aliasing=          		0
  -Wstrict-null-sentinel      		[disabled]
  -Wstrict-overflow           		
  -Wstrict-overflow=          		0
  -Wstrict-prototypes         		[disabled]
  -Wstrict-selector-match     		[disabled]
  -Wsuggest-attribute=const   		[disabled]
  -Wsuggest-attribute=format  		[disabled]
  -Wsuggest-attribute=noreturn 		[disabled]
  -Wsuggest-attribute=pure    		[disabled]
  -Wsuggest-final-methods     		[disabled]
  -Wsuggest-final-types       		[disabled]
  -Wsuggest-override          		[disabled]
  -Wsurprising                		[disabled]
  -Wswitch                    		[disabled]
  -Wswitch-bool               		[enabled]
  -Wswitch-default            		[disabled]
  -Wswitch-enum               		[disabled]
  -Wsync-nand                 		[enabled]
  -Wsynth                     		[disabled]
  -Wsystem-headers            		[disabled]
  -Wtabs                      		[disabled]
  -Wtarget-lifetime           		[disabled]
  -Wtraditional               		[disabled]
  -Wtraditional-conversion    		[disabled]
  -Wtrampolines               		[disabled]
  -Wtrigraphs                 		[enabled]
  -Wtype-limits               		[disabled]
  -Wundeclared-selector       		[disabled]
  -Wundef                     		[disabled]
  -Wunderflow                 		[enabled]
  -Wuninitialized             		[disabled]
  -Wunknown-pragmas           		[disabled]
  -Wunsafe-loop-optimizations 		[disabled]
  -Wunsuffixed-float-constants 		[disabled]
  -Wunused                    		[disabled]
  -Wunused-but-set-parameter  		[disabled]
  -Wunused-but-set-variable   		[disabled]
  -Wunused-dummy-argument     		[disabled]
  -Wunused-function           		[disabled]
  -Wunused-label              		[disabled]
  -Wunused-local-typedefs     		[disabled]
  -Wunused-macros             		[disabled]
  -Wunused-parameter          		[disabled]
  -Wunused-result             		[enabled]
  -Wunused-value              		[disabled]
  -Wunused-variable           		[disabled]
  -Wuse-without-only          		[disabled]
  -Wuseless-cast              		[disabled]
  -Wvarargs                   		[enabled]
  -Wvariadic-macros           		[disabled]
  -Wvector-operation-performance 	[disabled]
  -Wvirtual-move-assign       		[enabled]
  -Wvla                       		[enabled]
  -Wvolatile-register-var     		[disabled]
  -Wwrite-strings             		[disabled]
  -Wzero-as-null-pointer-constant 	[disabled]
  -Wzerotrip                  		[disabled]
  -frequire-return-statement  		[enabled]

関連項目




スポンサーリンク