Document the GDB 10.1 release in gdb/ChangeLog
[binutils-gdb.git] / gdbsupport / warning.m4
blob649be7552dd10942dbf983a83b69179b6316cf6c
1 dnl Autoconf configure script for GDB, the GNU debugger.
2 dnl Copyright (C) 1995-2020 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GDB.
5 dnl
6 dnl This program is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 3 of the License, or
9 dnl (at your option) any later version.
10 dnl
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 AC_DEFUN([AM_GDB_WARNINGS],[
20 AC_ARG_ENABLE(werror,
21   AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
22   [case "${enableval}" in
23      yes | y) ERROR_ON_WARNING="yes" ;;
24      no | n)  ERROR_ON_WARNING="no" ;;
25      *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
26    esac])
28 # Enable -Werror by default when using gcc.  Turn it off for releases.
29 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then
30     ERROR_ON_WARNING=yes
33 WERROR_CFLAGS=""
34 if test "${ERROR_ON_WARNING}" = yes ; then
35     WERROR_CFLAGS="-Werror"
38 # The options we'll try to enable.
39 build_warnings="-Wall -Wpointer-arith \
40 -Wno-unused -Wunused-value -Wunused-variable -Wunused-function \
41 -Wno-switch -Wno-char-subscripts \
42 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
43 -Wno-sign-compare -Wno-error=maybe-uninitialized \
44 -Wno-mismatched-tags \
45 -Wno-error=deprecated-register \
46 -Wsuggest-override \
47 -Wimplicit-fallthrough=3 \
48 -Wduplicated-cond \
49 -Wshadow=local \
50 -Wdeprecated-copy \
51 -Wdeprecated-copy-dtor \
52 -Wredundant-move \
53 -Wmissing-declarations \
54 -Wmissing-prototypes \
55 -Wstrict-null-sentinel \
58 case "${host}" in
59   *-*-mingw32*)
60     # Enable -Wno-format by default when using gcc on mingw since many
61     # GCC versions complain about %I64.
62     build_warnings="$build_warnings -Wno-format" ;;
63   *-*-solaris*)
64     # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
65     # doesn't understand.
66     build_warnings="$build_warnings -Wno-unknown-pragmas"
67     # Solaris 11 <unistd.h> marks vfork deprecated.
68     build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
69   *)
70     # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
71     # but there's a special case for this below.
72     build_warnings="$build_warnings -Wformat-nonliteral" ;;
73 esac
75 AC_ARG_ENABLE(build-warnings,
76 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
77 [case "${enableval}" in
78   yes)  ;;
79   no)   build_warnings="-w";;
80   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
81         build_warnings="${build_warnings} ${t}";;
82   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
83         build_warnings="${t} ${build_warnings}";;
84   *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
85 esac
86 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
87   echo "Setting compiler warning flags = $build_warnings" 6>&1
88 fi])dnl
89 AC_ARG_ENABLE(gdb-build-warnings,
90 AS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]),
91 [case "${enableval}" in
92   yes)  ;;
93   no)   build_warnings="-w";;
94   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
95         build_warnings="${build_warnings} ${t}";;
96   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
97         build_warnings="${t} ${build_warnings}";;
98   *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
99 esac
100 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
101   echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
102 fi])dnl
104 # The set of warnings supported by a C++ compiler is not the same as
105 # of the C compiler.
106 AC_LANG_PUSH([C++])
108 WARN_CFLAGS=""
109 if test "x${build_warnings}" != x -a "x$GCC" = xyes
110 then
111     AC_MSG_CHECKING(compiler warning flags)
112     # Separate out the -Werror flag as some files just cannot be
113     # compiled with it enabled.
114     for w in ${build_warnings}; do
115         # GCC does not complain about -Wno-unknown-warning.  Invert
116         # and test -Wunknown-warning instead.
117         case $w in
118         -Wno-*)
119                 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
120         -Wformat-nonliteral)
121                 # gcc requires -Wformat before -Wformat-nonliteral
122                 # will work, so stick them together.
123                 w="-Wformat $w"
124                 wtest="$w"
125                 ;;
126         *)
127                 wtest=$w ;;
128         esac
130         case $w in
131         -Werr*) WERROR_CFLAGS=-Werror ;;
132         *)
133             # Check whether GCC accepts it.
134             saved_CFLAGS="$CFLAGS"
135             CFLAGS="$CFLAGS -Werror $wtest"
136             saved_CXXFLAGS="$CXXFLAGS"
137             CXXFLAGS="$CXXFLAGS -Werror $wtest"
138             if test "x$w" = "x-Wunused-variable"; then
139               # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
140               # fixed in GCC 4.9.  This test is derived from the gdb
141               # source code that triggered this bug in GCC.
142               AC_TRY_COMPILE(
143                 [struct scoped_restore_base {};
144                  struct scoped_restore_tmpl : public scoped_restore_base {
145                    ~scoped_restore_tmpl() {}
146                  };],
147                 [const scoped_restore_base &b = scoped_restore_tmpl();],
148                 WARN_CFLAGS="${WARN_CFLAGS} $w",)
149             else
150               AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
151             fi
152             CFLAGS="$saved_CFLAGS"
153             CXXFLAGS="$saved_CXXFLAGS"
154         esac
155     done
156     AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
158 AC_SUBST(WARN_CFLAGS)
159 AC_SUBST(WERROR_CFLAGS)
161 AC_LANG_POP([C++])