PR c++/34950
[official-gcc.git] / contrib / check_warning_flags.sh
blob95640f7758d0cace22abd51b314fc0a225033820
1 #! /bin/sh
3 # Check that the warning flags documented in invoke.texi match up
4 # with what the compiler accepts.
6 # Copyright (C) 2008 Free Software Foundation, Inc.
7 # Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
9 # This script is Free Software, and it can be copied, distributed and
10 # modified as defined in the GNU General Public License. A copy of
11 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
13 # Call this script as
14 # check_warning_flags.sh path/to/invoke.texi
15 # with CC set to the compiler to be tested.
16 # The script scribbles in the current directory.
18 progname=`echo "$0" | sed 's,.*/,,'`
19 usage ()
21 echo "usage: $progname path/to/invoke.texi"
22 echo "set \$CC to the compiler to be checked"
23 exit 1
26 ret=0
27 LC_ALL=C
28 export LC_ALL
29 : ${CC=gcc}
30 test $# = 1 || usage
31 invoke_texi=$1
32 test -r "$invoke_texi" || {
33 echo "$progname: error: cannot read '$invoke_texi'" >&2
34 usage
36 filebase=check_warning_flags_file$$
37 stderr=check_warning_flags_stderr$$
39 remove_problematic_flags='
40 /-Wlarger-than-/d
41 /-W[alp],/d
42 /-Werror/d
43 /-Wpadded/d
44 /=/d'
46 # Ensure that indexed warnings are accepted.
47 set x `sed '/^@opindex W/{
48 s/^@opindex /-/
49 '"$remove_problematic_flags"'
50 /-W[alp]$/d
53 d' <"$invoke_texi"`
54 shift
55 : >$filebase.c
56 $CC -c $filebase.c "$@" 2>&1 |
57 grep -v 'command line option.*is valid for.*but not for' >$stderr
58 if test -s $stderr; then
59 echo "options listed in @opindex but not accepted by the compiler:" >&2
60 cat $stderr >&2
61 ret=1
63 rm -f $filebase.c $stderr
65 # Check documentation of warning options.
66 for lang in c c++ objc obj-c++; do
67 case $lang in
68 c) ext=c; langmatch='[^-]C[^+].*only' ;;
69 c++) ext=C; langmatch='[^-]C++.*only' ;;
70 objc) ext=m; langmatch='Objective-C[^+].*only' ;;
71 obj-c++) ext=M; langmatch='Objective-C++.*only' ;;
72 esac
73 file=$filebase.$ext
74 : >$file
75 $CC -c $file 2>$stderr
76 if grep 'not installed on this system' $stderr >/dev/null ||
77 grep 'installation problem, cannot exec' $stderr >/dev/null ||
78 grep 'error trying to exec' $stderr >/dev/null
79 then
80 echo "$progname: $CC is not configured for language $lang, skipping checks" >&2
81 rm -f $file $filebase.o $filebase.obj $stderr
82 continue
85 # Verify good warning flags.
86 set x `sed '
87 t a
89 /^@item -W/{
90 /'"$langmatch"'/b x
91 / only)/d
92 b x
96 '"$remove_problematic_flags"'
97 s/^@item //
98 s/ .*//
99 ' <"$invoke_texi"`
100 shift
101 $CC -c $file -O "$@" 2>$stderr
102 if test -s $stderr; then
103 echo failures: >&2
104 cat $stderr >&2
105 ret=1
108 # Verify bad warning flags.
109 set x `sed '
112 /^@item -W/{
113 / only)/!d
114 /'"$langmatch"'/d
119 '"$remove_problematic_flags"'
120 s/^@item //
121 s/ .*//
122 ' <"$invoke_texi"`
123 shift
124 $CC -c $file -O "$@" 2>$stderr
125 # cat $stderr >&2
126 test $# = `grep 'command line option.*valid.*but not for' <$stderr | wc -l` || {
127 for warning
129 grep "command line option.*$warning.*valid" <$stderr >&2 ||
130 echo "valid for $lang but not annotated as such: $warning"
131 done
132 ret=1
134 rm -f $file $filebase.o $filebase.obj $stderr
135 done
136 exit $ret