1# manywarnings.m4 serial 7 2dnl Copyright (C) 2008-2014 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7dnl From Simon Josefsson 8 9# gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) 10# -------------------------------------------------- 11# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. 12# Elements separated by whitespace. In set logic terms, the function 13# does OUTVAR = LISTVAR \ REMOVEVAR. 14AC_DEFUN([gl_MANYWARN_COMPLEMENT], 15[ 16 gl_warn_set= 17 set x $2; shift 18 for gl_warn_item 19 do 20 case " $3 " in 21 *" $gl_warn_item "*) 22 ;; 23 *) 24 gl_warn_set="$gl_warn_set $gl_warn_item" 25 ;; 26 esac 27 done 28 $1=$gl_warn_set 29]) 30 31# gl_MANYWARN_ALL_GCC(VARIABLE) 32# ----------------------------- 33# Add all documented GCC warning parameters to variable VARIABLE. 34# Note that you need to test them using gl_WARN_ADD if you want to 35# make sure your gcc understands it. 36AC_DEFUN([gl_MANYWARN_ALL_GCC], 37[ 38 dnl First, check for some issues that only occur when combining multiple 39 dnl gcc warning categories. 40 AC_REQUIRE([AC_PROG_CC]) 41 if test -n "$GCC"; then 42 43 dnl Check if -W -Werror -Wno-missing-field-initializers is supported 44 dnl with the current $CC $CFLAGS $CPPFLAGS. 45 AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported]) 46 AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [ 47 gl_save_CFLAGS="$CFLAGS" 48 CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers" 49 AC_COMPILE_IFELSE( 50 [AC_LANG_PROGRAM([[]], [[]])], 51 [gl_cv_cc_nomfi_supported=yes], 52 [gl_cv_cc_nomfi_supported=no]) 53 CFLAGS="$gl_save_CFLAGS"]) 54 AC_MSG_RESULT([$gl_cv_cc_nomfi_supported]) 55 56 if test "$gl_cv_cc_nomfi_supported" = yes; then 57 dnl Now check whether -Wno-missing-field-initializers is needed 58 dnl for the { 0, } construct. 59 AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed]) 60 AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [ 61 gl_save_CFLAGS="$CFLAGS" 62 CFLAGS="$CFLAGS -W -Werror" 63 AC_COMPILE_IFELSE( 64 [AC_LANG_PROGRAM( 65 [[void f (void) 66 { 67 typedef struct { int a; int b; } s_t; 68 s_t s1 = { 0, }; 69 } 70 ]], 71 [[]])], 72 [gl_cv_cc_nomfi_needed=no], 73 [gl_cv_cc_nomfi_needed=yes]) 74 CFLAGS="$gl_save_CFLAGS" 75 ]) 76 AC_MSG_RESULT([$gl_cv_cc_nomfi_needed]) 77 fi 78 79 dnl Next, check if -Werror -Wuninitialized is useful with the 80 dnl user's choice of $CFLAGS; some versions of gcc warn that it 81 dnl has no effect if -O is not also used 82 AC_MSG_CHECKING([whether -Wuninitialized is supported]) 83 AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [ 84 gl_save_CFLAGS="$CFLAGS" 85 CFLAGS="$CFLAGS -Werror -Wuninitialized" 86 AC_COMPILE_IFELSE( 87 [AC_LANG_PROGRAM([[]], [[]])], 88 [gl_cv_cc_uninitialized_supported=yes], 89 [gl_cv_cc_uninitialized_supported=no]) 90 CFLAGS="$gl_save_CFLAGS"]) 91 AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported]) 92 93 fi 94 95 # List all gcc warning categories. 96 # To compare this list to your installed GCC's, run this Bash command: 97 # 98 # comm -3 \ 99 # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \ 100 # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort | 101 # grep -v -x -f <( 102 # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec)) 103 104 gl_manywarn_set= 105 for gl_manywarn_item in \ 106 -W \ 107 -Wabi \ 108 -Waddress \ 109 -Waggressive-loop-optimizations \ 110 -Wall \ 111 -Warray-bounds \ 112 -Wattributes \ 113 -Wbad-function-cast \ 114 -Wbuiltin-macro-redefined \ 115 -Wcast-align \ 116 -Wchar-subscripts \ 117 -Wclobbered \ 118 -Wcomment \ 119 -Wcomments \ 120 -Wcoverage-mismatch \ 121 -Wcpp \ 122 -Wdate-time \ 123 -Wdeprecated \ 124 -Wdeprecated-declarations \ 125 -Wdisabled-optimization \ 126 -Wdiv-by-zero \ 127 -Wdouble-promotion \ 128 -Wempty-body \ 129 -Wendif-labels \ 130 -Wenum-compare \ 131 -Wextra \ 132 -Wformat-contains-nul \ 133 -Wformat-extra-args \ 134 -Wformat-nonliteral \ 135 -Wformat-security \ 136 -Wformat-y2k \ 137 -Wformat-zero-length \ 138 -Wfree-nonheap-object \ 139 -Wignored-qualifiers \ 140 -Wimplicit \ 141 -Wimplicit-function-declaration \ 142 -Wimplicit-int \ 143 -Winit-self \ 144 -Winline \ 145 -Wint-to-pointer-cast \ 146 -Winvalid-memory-model \ 147 -Winvalid-pch \ 148 -Wjump-misses-init \ 149 -Wlogical-op \ 150 -Wmain \ 151 -Wmaybe-uninitialized \ 152 -Wmissing-braces \ 153 -Wmissing-declarations \ 154 -Wmissing-field-initializers \ 155 -Wmissing-include-dirs \ 156 -Wmissing-parameter-type \ 157 -Wmissing-prototypes \ 158 -Wmultichar \ 159 -Wnarrowing \ 160 -Wnested-externs \ 161 -Wnonnull \ 162 -Wold-style-declaration \ 163 -Wold-style-definition \ 164 -Wopenmp-simd \ 165 -Woverflow \ 166 -Woverlength-strings \ 167 -Woverride-init \ 168 -Wpacked \ 169 -Wpacked-bitfield-compat \ 170 -Wparentheses \ 171 -Wpointer-arith \ 172 -Wpointer-sign \ 173 -Wpointer-to-int-cast \ 174 -Wpragmas \ 175 -Wreturn-local-addr \ 176 -Wreturn-type \ 177 -Wsequence-point \ 178 -Wshadow \ 179 -Wsizeof-pointer-memaccess \ 180 -Wstack-protector \ 181 -Wstrict-aliasing \ 182 -Wstrict-overflow \ 183 -Wstrict-prototypes \ 184 -Wsuggest-attribute=const \ 185 -Wsuggest-attribute=format \ 186 -Wsuggest-attribute=noreturn \ 187 -Wsuggest-attribute=pure \ 188 -Wswitch \ 189 -Wswitch-default \ 190 -Wsync-nand \ 191 -Wsystem-headers \ 192 -Wtrampolines \ 193 -Wtrigraphs \ 194 -Wtype-limits \ 195 -Wuninitialized \ 196 -Wunknown-pragmas \ 197 -Wunsafe-loop-optimizations \ 198 -Wunused \ 199 -Wunused-but-set-parameter \ 200 -Wunused-but-set-variable \ 201 -Wunused-function \ 202 -Wunused-label \ 203 -Wunused-local-typedefs \ 204 -Wunused-macros \ 205 -Wunused-parameter \ 206 -Wunused-result \ 207 -Wunused-value \ 208 -Wunused-variable \ 209 -Wvarargs \ 210 -Wvariadic-macros \ 211 -Wvector-operation-performance \ 212 -Wvla \ 213 -Wvolatile-register-var \ 214 -Wwrite-strings \ 215 \ 216 ; do 217 gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item" 218 done 219 220 # gcc --help=warnings outputs an unusual form for this option; list 221 # it here so that the above 'comm' command doesn't report a false match. 222 gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc" 223 224 # These are needed for older GCC versions. 225 if test -n "$GCC"; then 226 case `($CC --version) 2>/dev/null` in 227 'gcc (GCC) '[[0-3]].* | \ 228 'gcc (GCC) '4.[[0-7]].*) 229 gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option" 230 gl_manywarn_set="$gl_manywarn_set -funit-at-a-time" 231 ;; 232 esac 233 fi 234 235 # Disable specific options as needed. 236 if test "$gl_cv_cc_nomfi_needed" = yes; then 237 gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers" 238 fi 239 240 if test "$gl_cv_cc_uninitialized_supported" = no; then 241 gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized" 242 fi 243 244 $1=$gl_manywarn_set 245]) 246