xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/warning.m4 (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
1dnl Autoconf configure script for GDB, the GNU debugger.
2dnl Copyright (C) 1995-2024 Free Software Foundation, Inc.
3dnl
4dnl This file is part of GDB.
5dnl
6dnl This program is free software; you can redistribute it and/or modify
7dnl it under the terms of the GNU General Public License as published by
8dnl the Free Software Foundation; either version 3 of the License, or
9dnl (at your option) any later version.
10dnl
11dnl This program is distributed in the hope that it will be useful,
12dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14dnl GNU General Public License for more details.
15dnl
16dnl You should have received a copy of the GNU General Public License
17dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19AC_DEFUN([AM_GDB_WARNINGS],[
20AC_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])
27
28# Enable -Werror by default when using gcc.  Turn it off for releases.
29if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then
30    ERROR_ON_WARNING=yes
31fi
32
33WERROR_CFLAGS=""
34if test "${ERROR_ON_WARNING}" = yes ; then
35    WERROR_CFLAGS="-Werror"
36fi
37
38# The options we'll try to enable.
39build_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=5 \
48-Wduplicated-cond \
49-Wshadow=local \
50-Wdeprecated-copy \
51-Wdeprecated-copy-dtor \
52-Wredundant-move \
53-Wmissing-declarations \
54-Wstrict-null-sentinel \
55-Wno-vla-cxx-extension \
56"
57
58# The -Wmissing-prototypes flag will be accepted by GCC, but results
59# in a warning being printed about the flag not being valid for C++,
60# this is something to do with using ccache, and argument ordering.
61if test "$GDB_COMPILER_TYPE" != gcc; then
62  build_warnings="$build_warnings -Wmissing-prototypes"
63fi
64
65case "${host}" in
66  *-*-mingw32*)
67    # Enable -Wno-format by default when using gcc on mingw since many
68    # GCC versions complain about %I64.
69    build_warnings="$build_warnings -Wno-format" ;;
70  *-*-solaris*)
71    # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
72    # doesn't understand.
73    build_warnings="$build_warnings -Wno-unknown-pragmas"
74    # Solaris 11 <unistd.h> marks vfork deprecated.
75    build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
76  *)
77    # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
78    # but there's a special case for this below.
79    build_warnings="$build_warnings -Wformat-nonliteral" ;;
80esac
81
82AC_ARG_ENABLE(build-warnings,
83AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
84[case "${enableval}" in
85  yes)	;;
86  no)	build_warnings="-w";;
87  ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
88        build_warnings="${build_warnings} ${t}";;
89  *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
90        build_warnings="${t} ${build_warnings}";;
91  *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
92esac
93if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
94  echo "Setting compiler warning flags = $build_warnings" 6>&1
95fi])dnl
96AC_ARG_ENABLE(gdb-build-warnings,
97AS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]),
98[case "${enableval}" in
99  yes)	;;
100  no)	build_warnings="-w";;
101  ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
102        build_warnings="${build_warnings} ${t}";;
103  *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
104        build_warnings="${t} ${build_warnings}";;
105  *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
106esac
107if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
108  echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
109fi])dnl
110
111# The set of warnings supported by a C++ compiler is not the same as
112# of the C compiler.
113AC_LANG_PUSH([C++])
114
115WARN_CFLAGS=""
116if test "x${build_warnings}" != x -a "x$GCC" = xyes
117then
118    AC_MSG_CHECKING(compiler warning flags)
119    # Separate out the -Werror flag as some files just cannot be
120    # compiled with it enabled.
121    for w in ${build_warnings}; do
122	# GCC does not complain about -Wno-unknown-warning.  Invert
123	# and test -Wunknown-warning instead.
124	case $w in
125	-Wno-*)
126		wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
127        -Wformat-nonliteral)
128		# gcc requires -Wformat before -Wformat-nonliteral
129		# will work, so stick them together.
130		w="-Wformat $w"
131		wtest="$w"
132		;;
133	*)
134		wtest=$w ;;
135	esac
136
137	case $w in
138	-Werr*) WERROR_CFLAGS=-Werror ;;
139	*)
140	    # Check whether GCC accepts it.
141	    saved_CFLAGS="$CFLAGS"
142	    CFLAGS="$CFLAGS -Werror $wtest"
143	    saved_CXXFLAGS="$CXXFLAGS"
144	    CXXFLAGS="$CXXFLAGS -Werror $wtest"
145	    if test "x$w" = "x-Wunused-variable"; then
146	      # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
147	      # fixed in GCC 4.9.  This test is derived from the gdb
148	      # source code that triggered this bug in GCC.
149	      AC_COMPILE_IFELSE(
150		[AC_LANG_PROGRAM(
151		   [struct scoped_restore_base {};
152		    struct scoped_restore_tmpl : public scoped_restore_base {
153		      ~scoped_restore_tmpl() {}
154		    };],
155		   [const scoped_restore_base &b = scoped_restore_tmpl();]
156		 )],
157		[WARN_CFLAGS="${WARN_CFLAGS} $w"],
158		[]
159	      )
160	    else
161	      AC_COMPILE_IFELSE(
162		[AC_LANG_PROGRAM([], [])],
163		[WARN_CFLAGS="${WARN_CFLAGS} $w"],
164		[]
165	      )
166	    fi
167	    CFLAGS="$saved_CFLAGS"
168	    CXXFLAGS="$saved_CXXFLAGS"
169	esac
170    done
171    AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
172fi
173AC_SUBST(WARN_CFLAGS)
174AC_SUBST(WERROR_CFLAGS)
175
176AC_LANG_POP([C++])
177])
178