warning.m4 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. dnl Autoconf configure script for GDB, the GNU debugger.
  2. dnl Copyright (C) 1995-2022 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/>.
  18. AC_DEFUN([AM_GDB_WARNINGS],[
  19. AC_ARG_ENABLE(werror,
  20. AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
  21. [case "${enableval}" in
  22. yes | y) ERROR_ON_WARNING="yes" ;;
  23. no | n) ERROR_ON_WARNING="no" ;;
  24. *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
  25. esac])
  26. # Enable -Werror by default when using gcc. Turn it off for releases.
  27. if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then
  28. ERROR_ON_WARNING=yes
  29. fi
  30. WERROR_CFLAGS=""
  31. if test "${ERROR_ON_WARNING}" = yes ; then
  32. WERROR_CFLAGS="-Werror"
  33. fi
  34. # The options we'll try to enable.
  35. build_warnings="-Wall -Wpointer-arith \
  36. -Wno-unused -Wunused-value -Wunused-variable -Wunused-function \
  37. -Wno-switch -Wno-char-subscripts \
  38. -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
  39. -Wno-sign-compare -Wno-error=maybe-uninitialized \
  40. -Wno-mismatched-tags \
  41. -Wno-error=deprecated-register \
  42. -Wsuggest-override \
  43. -Wimplicit-fallthrough=3 \
  44. -Wduplicated-cond \
  45. -Wshadow=local \
  46. -Wdeprecated-copy \
  47. -Wdeprecated-copy-dtor \
  48. -Wredundant-move \
  49. -Wmissing-declarations \
  50. -Wstrict-null-sentinel \
  51. "
  52. # The -Wmissing-prototypes flag will be accepted by GCC, but results
  53. # in a warning being printed about the flag not being valid for C++,
  54. # this is something to do with using ccache, and argument ordering.
  55. if test "$GDB_COMPILER_TYPE" != gcc; then
  56. build_warnings="$build_warnings -Wmissing-prototypes"
  57. fi
  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
  74. AC_ARG_ENABLE(build-warnings,
  75. AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
  76. [case "${enableval}" in
  77. yes) ;;
  78. no) build_warnings="-w";;
  79. ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  80. build_warnings="${build_warnings} ${t}";;
  81. *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  82. build_warnings="${t} ${build_warnings}";;
  83. *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
  84. esac
  85. if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
  86. echo "Setting compiler warning flags = $build_warnings" 6>&1
  87. fi])dnl
  88. AC_ARG_ENABLE(gdb-build-warnings,
  89. AS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]),
  90. [case "${enableval}" in
  91. yes) ;;
  92. no) build_warnings="-w";;
  93. ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  94. build_warnings="${build_warnings} ${t}";;
  95. *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  96. build_warnings="${t} ${build_warnings}";;
  97. *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
  98. esac
  99. if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
  100. echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
  101. fi])dnl
  102. # The set of warnings supported by a C++ compiler is not the same as
  103. # of the C compiler.
  104. AC_LANG_PUSH([C++])
  105. WARN_CFLAGS=""
  106. if test "x${build_warnings}" != x -a "x$GCC" = xyes
  107. then
  108. AC_MSG_CHECKING(compiler warning flags)
  109. # Separate out the -Werror flag as some files just cannot be
  110. # compiled with it enabled.
  111. for w in ${build_warnings}; do
  112. # GCC does not complain about -Wno-unknown-warning. Invert
  113. # and test -Wunknown-warning instead.
  114. case $w in
  115. -Wno-*)
  116. wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
  117. -Wformat-nonliteral)
  118. # gcc requires -Wformat before -Wformat-nonliteral
  119. # will work, so stick them together.
  120. w="-Wformat $w"
  121. wtest="$w"
  122. ;;
  123. *)
  124. wtest=$w ;;
  125. esac
  126. case $w in
  127. -Werr*) WERROR_CFLAGS=-Werror ;;
  128. *)
  129. # Check whether GCC accepts it.
  130. saved_CFLAGS="$CFLAGS"
  131. CFLAGS="$CFLAGS -Werror $wtest"
  132. saved_CXXFLAGS="$CXXFLAGS"
  133. CXXFLAGS="$CXXFLAGS -Werror $wtest"
  134. if test "x$w" = "x-Wunused-variable"; then
  135. # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
  136. # fixed in GCC 4.9. This test is derived from the gdb
  137. # source code that triggered this bug in GCC.
  138. AC_COMPILE_IFELSE(
  139. [AC_LANG_PROGRAM(
  140. [struct scoped_restore_base {};
  141. struct scoped_restore_tmpl : public scoped_restore_base {
  142. ~scoped_restore_tmpl() {}
  143. };],
  144. [const scoped_restore_base &b = scoped_restore_tmpl();]
  145. )],
  146. [WARN_CFLAGS="${WARN_CFLAGS} $w"],
  147. []
  148. )
  149. else
  150. AC_COMPILE_IFELSE(
  151. [AC_LANG_PROGRAM([], [])],
  152. [WARN_CFLAGS="${WARN_CFLAGS} $w"],
  153. []
  154. )
  155. fi
  156. CFLAGS="$saved_CFLAGS"
  157. CXXFLAGS="$saved_CXXFLAGS"
  158. esac
  159. done
  160. AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
  161. fi
  162. AC_SUBST(WARN_CFLAGS)
  163. AC_SUBST(WERROR_CFLAGS)
  164. AC_LANG_POP([C++])
  165. ])