/
slg_gcc_all_warnings.m4
107 lines (90 loc) · 3.16 KB
/
slg_gcc_all_warnings.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
################################################################
#
# Enable all the compiler debugging we can find
# Simson L. Garfinkel
#
# This is originally from PhotoRec, but modified substantially by Simson
# Figure out which flags we can use with the compiler.
#
# These I don't like:
# -Wdeclaration-after-statement -Wconversion
# doesn't work: -Wunreachable-code
# causes configure to crash on gcc-4.2.1: -Wsign-compare-Winline
# causes warnings with unistd.h: -Wnested-externs
# Just causes too much annoyance: -Wmissing-format-attribute
# First, see if we are using CLANG
using_clang=no
if (g++ --version 2>&1 | grep clang > /dev/null) ;
then
AC_MSG_NOTICE([g++ is really clang++])
using_clang=yes
fi
if test x$CXX == "xclang++" ; then
using_clang=yes
fi
# Check GCC
C_WARNINGS_TO_TEST="-MD -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes \
-Wshadow -Wwrite-strings -Wcast-align -Waggregate-return \
-Wbad-function-cast -Wcast-qual -Wundef -Wredundant-decls -Wdisabled-optimization \
-Wfloat-equal -Wmultichar -Wc++-compat -Wmissing-noreturn "
if test x"${mingw}" != "xyes" ; then
# add the warnings we do not want to do on mingw
C_WARNINGS_TO_TEST="$C_WARNINGS_TO_TEST -Wall -Wstrict-prototypes"
fi
if test $using_clang == "no" ; then
# -Wstrict-null-sentinel is not supported under clang
CXX_WARNINGS_TO_TEST="$CXX_WARNINGS_TO_TEST -Wstrict-null-sentinel"
fi
echo "C Warnings to test: $C_WARNINGS_TO_TEST"
for option in $C_WARNINGS_TO_TEST
do
SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $option"
AC_MSG_CHECKING([whether gcc understands $option])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[has_option=yes],
[has_option=no; CFLAGS="$SAVE_CFLAGS"])
AC_MSG_RESULT($has_option)
unset has_option
unset SAVE_CFLAGS
if test $option = "-Wmissing-format-attribute" ; then
AC_DEFINE(HAVE_MISSING_FORMAT_ATTRIBUTE_WARNING,1,
[Indicates that we have the -Wmissing-format-attribute G++ warning])
fi
done
unset option
# Check G++
# We don't use these warnings:
# -Waggregate-return -- aggregate returns are GOOD; they simplify code design
# We can use these warnings after ZLIB gets upgraded:
# -Wundef --- causes problems with zlib
# -Wcast-qual
# -Wmissing-format-attribute --- Just too annoying
AC_LANG_PUSH(C++)
AC_CHECK_HEADERS([string])
CXX_WARNINGS_TO_TEST="-Wall -MD -D_FORTIFY_SOURCE=2 -Wpointer-arith \
-Wshadow -Wwrite-strings -Wcast-align \
-Wredundant-decls -Wdisabled-optimization \
-Wfloat-equal -Wmultichar -Wmissing-noreturn \
-Woverloaded-virtual -Wsign-promo \
-fno-new-ttp-matching \
-funit-at-a-time"
if test x"${mingw}" != "xyes" ; then
# add the warnings we don't want to do on mingw
CXX_WARNINGS_TO_TEST="$CXX_WARNINGS_TO_TEST -Weffc++"
fi
echo "C++ Warnings to test: $CXX_WARNINGS_TO_TEST"
for option in $CXX_WARNINGS_TO_TEST
do
SAVE_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $option"
AC_MSG_CHECKING([whether g++ understands $option])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[has_option=yes],
[has_option=no; CXXFLAGS="$SAVE_CXXFLAGS"])
AC_MSG_RESULT($has_option)
unset has_option
unset SAVE_CXXFLAGS
done
unset option
AC_LANG_POP()