diff options
author | Reuben Thomas <rrt@sc3d.org> | 2017-02-20 14:36:10 +0000 |
---|---|---|
committer | Reuben Thomas <rrt@sc3d.org> | 2017-02-20 22:57:38 +0000 |
commit | 936827fd7152fe4d01449eeb214d828d545102f8 (patch) | |
tree | 906bd12f6f8919e6da5dbad3c7fbaf62371f3523 | |
parent | 3f89992378adc4c5ce4365a75d415c8e9abd116c (diff) | |
download | enchant-936827fd7152fe4d01449eeb214d828d545102f8.tar.gz |
Overhaul compiler warning flags
Use gnulib’s manywarnings module for C, and adapt it to make a C++ version.
Fix resulting warnings that are not in system headers (can’t be avoided as
pkg-config supplies -I flags, not -isystem flags) or non-trivial (a couple
in ispell library).
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | bootstrap.conf | 5 | ||||
-rw-r--r-- | configure.ac | 173 | ||||
-rw-r--r-- | gl/build-aux/g++-warning.spec | 100 | ||||
-rw-r--r-- | gl/m4/manywarnings-cxx.m4 | 288 | ||||
-rw-r--r-- | gl/modules/manywarnings-cxx | 16 | ||||
-rw-r--r-- | m4/.gitignore | 3 | ||||
-rw-r--r-- | m4/gnulib-cache.m4 | 5 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/aspell/Makefile.am | 2 | ||||
-rw-r--r-- | src/aspell/aspell_provider.c | 15 | ||||
-rw-r--r-- | src/enchant-lsmod.c | 11 | ||||
-rw-r--r-- | src/enchant.c | 23 | ||||
-rw-r--r-- | src/hspell/Makefile.am | 2 | ||||
-rw-r--r-- | src/hspell/hspell_provider.c | 13 | ||||
-rw-r--r-- | src/ispell/Makefile.am | 2 | ||||
-rw-r--r-- | src/ispell/ispell_checker.cpp | 94 | ||||
-rw-r--r-- | src/ispell/ispell_checker.h | 2 | ||||
-rw-r--r-- | src/myspell/Makefile.am | 2 | ||||
-rw-r--r-- | src/myspell/myspell_checker.cpp | 67 | ||||
-rw-r--r-- | src/pwl.c | 10 | ||||
-rw-r--r-- | src/uspell/Makefile.am | 2 | ||||
-rw-r--r-- | src/voikko/Makefile.am | 2 | ||||
-rw-r--r-- | src/voikko/voikko_provider.c | 20 | ||||
-rw-r--r-- | src/zemberek/Makefile.am | 2 |
25 files changed, 630 insertions, 232 deletions
@@ -1,3 +1,4 @@ +*~ *.o *.lo *.la diff --git a/bootstrap.conf b/bootstrap.conf index 3b9b799..de3293e 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -1,4 +1,4 @@ -# bootstrap.conf (GNU zile) version 2017-02-10 +# bootstrap.conf (GNU zile) version 2017-02-20 # Written by Gary V. Vaughan, 2010 # Copyright (C) 2010 Free Software Foundation, Inc. @@ -47,6 +47,9 @@ gnulib_tool_options=' gnulib_modules=' bootstrap flock + manywarnings + manywarnings-cxx + snippet/unused-parameter ' diff --git a/configure.ac b/configure.ac index 93d1357..3d92a6d 100644 --- a/configure.ac +++ b/configure.ac @@ -55,129 +55,58 @@ PKG_PROG_PKG_CONFIG PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.6 gmodule-2.0]) -dnl =========================================================================== -dnl check compiler flags -AC_DEFUN([ENCHANT_CC_TRY_FLAG], [ - AC_MSG_CHECKING([whether $CC supports $1]) - - enchant_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $1" - - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])], [enchant_cc_flag=yes], [enchant_cc_flag=no]) - CFLAGS="$enchant_save_CFLAGS" - - if test "x$enchant_cc_flag" = "xyes"; then - ifelse([$2], , :, [$2]) - else - ifelse([$3], , :, [$3]) - fi - AC_MSG_RESULT([$enchant_cc_flag]) -]) - -dnl check compiler flags -AC_DEFUN([ENCHANT_CXX_TRY_FLAG], [ - AC_MSG_CHECKING([whether $CXX supports $1]) - - AC_LANG_PUSH(C++) - enchant_save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS $1" - - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]])], [enchant_cxx_flag=yes], [enchant_cxx_flag=no]) - CXXFLAGS="$enchant_save_CXXFLAGS" - - if test "x$enchant_cxx_flag" = "xyes"; then - ifelse([$2], , :, [$2]) - else - ifelse([$3], , :, [$3]) - fi - AC_MSG_RESULT([$enchant_cxx_flag]) - AC_LANG_POP(C++) -]) - -dnl Use lots of warning flags with gcc and compatible compilers - -dnl Note: if you change the following variable, the cache is automatically -dnl skipped and all flags rechecked. So there's no need to do anything -dnl else. If for any reason you need to force a recheck, just change -dnl MAYBE_WARN in an ignorable way (like adding whitespace) - -CC_MAYBE_WARN="-Wall -Wextra \ --Wsign-compare -Werror-implicit-function-declaration \ --Wpointer-arith -Wwrite-strings -Wstrict-prototypes \ --Wmissing-prototypes -Wmissing-declarations -Wnested-externs \ --Wpacked -Wswitch-enum -Wmissing-format-attribute \ --Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \ --Wdeclaration-after-statement -Wold-style-definition \ --Wno-missing-field-initializers -Wno-unused-parameter \ --Wno-attributes -Wno-long-long -Winline -fno-strict-aliasing" - -# invalidate cached value if MAYBE_WARN has changed -if test "x$enchant_cv_warn_maybe" != "x$CC_MAYBE_WARN"; then - unset enchant_cv_warn_cflags -fi -AC_CACHE_CHECK([for supported C warning flags], enchant_cv_warn_cflags, [ - echo - CC_WARN_CFLAGS="" - - # Some warning options are not supported by all versions of - # gcc, so test all desired options against the current - # compiler. - # - # Note that there are some order dependencies - # here. Specifically, an option that disables a warning will - # have no net effect if a later option then enables that - # warnings, (perhaps implicitly). So we put some grouped - # options (-Wall and -Wextra) up front and the -Wno options - # last. - - for W in $CC_MAYBE_WARN; do - ENCHANT_CC_TRY_FLAG([$W], [CC_WARN_CFLAGS="$CC_WARN_CFLAGS $W"]) - done - - enchant_cv_warn_cflags=$CC_WARN_CFLAGS - enchant_cv_warn_maybe=$CC_MAYBE_WARN - - AC_MSG_CHECKING([which C warning flags were supported])]) -CC_WARN_CFLAGS="$enchant_cv_warn_cflags" -AC_SUBST(CC_WARN_CFLAGS) - -CXX_MAYBE_WARN="-Wall -Wextra \ --Wsign-compare \ --Wpointer-arith -Wwrite-strings \ --Wpacked -Wswitch-enum -Wmissing-format-attribute \ --Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \ --Wno-missing-field-initializers -Wno-unused-parameter \ --Wno-attributes -Wno-long-long -Winline -fno-strict-aliasing" - -# invalidate cached value if MAYBE_WARN has changed -if test "x$enchant_cxx_cv_warn_maybe" != "x$CXX_MAYBE_WARN"; then - unset enchant_cxx_cv_warn_cflags +dnl Extra warnings with GCC and compatible compilers +AC_ARG_ENABLE([gcc-warnings], + [AS_HELP_STRING([--disable-gcc-warnings], + [turn off lots of GCC warnings])], + [case $enableval in + yes|no) ;; + *) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;; + esac + gl_gcc_warnings=$enableval], + [gl_gcc_warnings=yes] +) +if test "$gl_gcc_warnings" = yes; then + dnl Set up the list of undesired warnings. + nw= + nw="$nw -Wsystem-headers" # Don’t let system headers trigger warnings + nw="$nw -Wundef" # All compiler preprocessors support #if UNDEF + nw="$nw -Wtraditional" # All compilers nowadays support ANSI C + nw="$nw -Wdeclaration-after-statement" # We require C99. + nw="$nw -Wstrict-overflow" # Use a lower level (see below). + nw="$nw -Wconversion" # These warnings usually don’t point to mistakes. + nw="$nw -Wsign-conversion" # Likewise. + + gl_MANYWARN_ALL_GCC([warnings]) + + dnl Enable all GCC warnings not in this list. + gl_MANYWARN_COMPLEMENT([warnings], [$warnings], [$nw]) + for w in $warnings; do + gl_WARN_ADD([$w]) + done + + gl_MANYWARN_ALL_GXX([cxx_warnings]) + + dnl Enable all G++ warnings not in this list. + gl_MANYWARN_COMPLEMENT([cxx_warnings], [$cxx_warnings], [$nw]) + for w in $cxx_warnings; do + gl_CXX_WARN_ADD([$w]) + done + + dnl Add an extra warning + gl_WARN_ADD([-Wstrict-overflow=1]) + dnl Add some more safety measures + gl_WARN_ADD([-D_FORTIFY_SOURCE=2]) + dnl Remove a warning being promoted to error: we trigger this and can't turn it off with pragmas. + gl_WARN_ADD([-Wno-error=format-security]) + + # When compiling with GCC, prefer -isystem to -I when including system + # include files, to avoid generating useless diagnostics for the files. + ISYSTEM='-isystem ' +else + ISYSTEM='-I' fi -AC_CACHE_CHECK([for supported C++ warning flags], enchant_cxx_cv_warn_cflags, [ - echo - CXX_WARN_CFLAGS="" - - # Some warning options are not supported by all versions of - # gcc, so test all desired options against the current - # compiler. - # - # Note that there are some order dependencies - # here. Specifically, an option that disables a warning will - # have no net effect if a later option then enables that - # warnings, (perhaps implicitly). So we put some grouped - # options (-Wall and -Wextra) up front and the -Wno options - # last. - - for W in $CXX_MAYBE_WARN; do - ENCHANT_CXX_TRY_FLAG([$W], [CXX_WARN_CFLAGS="$CXX_WARN_CFLAGS $W"]) - done - - enchant_cxx_cv_warn_cflags=$CXX_WARN_CFLAGS - enchant_cxx_cv_warn_maybe=$CXX_MAYBE_WARN - - AC_MSG_CHECKING([which C++ warning flags were supported])]) -CXX_WARN_CFLAGS="$enchant_cxx_cv_warn_cflags" -AC_SUBST(CXX_WARN_CFLAGS) +AC_SUBST([ISYSTEM]) ENCHANT_CFLAGS=$GLIB_CFLAGS ENCHANT_LIBS=$GLIB_LIBS diff --git a/gl/build-aux/g++-warning.spec b/gl/build-aux/g++-warning.spec new file mode 100644 index 0000000..ae3e866 --- /dev/null +++ b/gl/build-aux/g++-warning.spec @@ -0,0 +1,100 @@ +# options to filter out, and why +--all-warnings alias for -Wall +--extra-warnings alias for -Wextra +-frequire-return-statement go +-Waggregate-return obsolescent +-Waliasing fortran +-Walign-commons fortran +-Wampersand fortran +-Warray-bounds covered by -Warray-bounds= +-Warray-bounds= handled specially by gl_MANYWARN_ALL_GCC +-Warray-temporaries fortran +-Wassign-intercept objc/objc++ +-Wbad-function-cast c +-Wc++0x-compat c++ compatibility +-Wc++11-compat c++ compatibility +-Wc++14-compat c++ compatibility +-Wc90-c99-compat c compatibility +-Wc99-c11-compat c compatibility +-Wcast-qual FIXME maybe? too much noise; encourages bad changes +-Wcast-result d +-Wc-binding-type fortran +-Wc++-compat FIXME maybe? borderline. some will want this +-Wcharacter-truncation fortran +-Wcompare-reals fortran +-Wconversion-extra fortran +-Wconversion FIXME maybe? too much noise; encourages bad changes +-Wdeclaration-after-statement FIXME: do not want. others may +-Wdesignated-init c +-Wdiscarded-array-qualifiers c +-Wdiscarded-qualifiers c +-Werror-implicit-function-declaration deprecated +-Wfloat-conversion FIXME maybe? borderline. some will want this +-Wfloat-equal FIXME maybe? borderline. some will want this +-Wformat covered by -Wformat=2 +-Wformat= gcc --help=warnings artifact +-Wframe-larger-than=<number> FIXME: choose something sane? +-Wfunction-elimination fortran +-Wimplicit c +-Wimplicit-function-declaration c +-Wimplicit-int c +-Wimplicit-interface fortran +-Wimplicit-procedure fortran +-Wincompatible-pointer-types c +-Wint-conversion c +-Winteger-division fortran +-Wintrinsic-shadow fortran +-Wintrinsics-std fortran +-Wjump-misses-init c +-Wlarger-than- gcc --help=warnings artifact +-Wlarger-than=<number> FIXME: choose something sane? +-Wline-truncation fortran +-Wlong-long obsolescent +-Wmissing-format-attribute obsolescent +-Wmissing-noreturn obsolescent +-Wmissing-parameter-type c +-Wmissing-prototypes c +-Wnested-externs c +-Wnormalized covered by -Wnormalized= +-Wnormalized=<none|id|nfc|nfkc> handled specially by gl_MANYWARN_ALL_GCC +-Wold-style-declaration c +-Wold-style-definition c +-Woverride-init c +-Wpadded FIXME maybe? warns about "stabil" member in /usr/include/bits/timex.h +-Wpedantic FIXME: too strict? +-Wpointer-sign c +-Wpointer-to-int-cast c +-Wproperty-assign-default objc++ +-Wprotocol objc++ +-Wrealloc-lhs-all fortran +-Wrealloc-lhs fortran +-Wreal-q-constant fortran +-Wredundant-decls FIXME maybe? many _gl_cxxalias_dummy FPs +-Wselector objc and objc++ +-Wshadow-ivar objc +-Wshift-overflow covered by -Wshift-overflow=2 +-Wshift-overflow= gcc --help=warnings artifact +-Wsign-compare FIXME maybe? borderline. some will want this +-Wsign-conversion FIXME maybe? borderline. some will want this +-Wstack-usage= FIXME: choose something sane? +-Wstrict-aliasing= FIXME: choose something sane? +-Wstrict-overflow= FIXME: choose something sane? +-Wstrict-prototypes c +-Wstrict-selector-match objc and objc++ +-Wsurprising fortran +-Wswitch-enum FIXME maybe? borderline. some will want this +-Wsynth deprecated +-Wtabs fortran +-Wtarget-lifetime fortran +-Wtraditional-conversion obsolescent +-Wtraditional obsolescent +-Wundeclared-selector objc and objc++ +-Wundef FIXME maybe? too many false positives +-Wunderflow fortran +-Wunreachable-code obsolescent no-op +-Wunsuffixed-float-constants triggers warning in gnulib's timespec.h +-Wunused-const-variable covered by -Wunusec-const-variable=2 +-Wunused-const-variable= gcc --help=warnings artifact +-Wunused-dummy-argument fortran +-Wuse-without-only fortran +-Wzerotrip fortran diff --git a/gl/m4/manywarnings-cxx.m4 b/gl/m4/manywarnings-cxx.m4 new file mode 100644 index 0000000..12c81b9 --- /dev/null +++ b/gl/m4/manywarnings-cxx.m4 @@ -0,0 +1,288 @@ +# manywarnings.m4 serial 8 +dnl Copyright (C) 2008-2017 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Simon Josefsson + +# gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR) +# -------------------------------------------------- +# Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR. +# Elements separated by whitespace. In set logic terms, the function +# does OUTVAR = LISTVAR \ REMOVEVAR. +AC_DEFUN([gl_MANYWARN_COMPLEMENT], +[ + gl_warn_set= + set x $2; shift + for gl_warn_item + do + case " $3 " in + *" $gl_warn_item "*) + ;; + *) + gl_warn_set="$gl_warn_set $gl_warn_item" + ;; + esac + done + $1=$gl_warn_set +]) + +# gl_MANYWARN_ALL_GXX(VARIABLE) +# ----------------------------- +# Add all documented G++ warning parameters to variable VARIABLE. +# Note that you need to test them using gl_WARN_ADD if you want to +# make sure your gcc understands it. +AC_DEFUN([gl_MANYWARN_ALL_GXX], +[ + dnl First, check for some issues that only occur when combining multiple + dnl gcc warning categories. + AC_REQUIRE([AC_PROG_CXX]) + if test -n "$GXX"; then + + dnl Check if -W -Werror -Wno-missing-field-initializers is supported + dnl with the current $CXX $CXXFLAGS $CPPFLAGS. + AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported]) + AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [ + gl_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -W -Werror -Wno-missing-field-initializers" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_nomfi_supported=yes], + [gl_cv_cc_nomfi_supported=no]) + CXXFLAGS="$gl_save_CXXFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_nomfi_supported]) + + if test "$gl_cv_cc_nomfi_supported" = yes; then + dnl Now check whether -Wno-missing-field-initializers is needed + dnl for the { 0, } construct. + AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed]) + AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [ + gl_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -W -Werror" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[int f (void) + { + typedef struct { int a; int b; } s_t; + s_t s1 = { 0, }; + return s1.b; + } + ]], + [[]])], + [gl_cv_cc_nomfi_needed=no], + [gl_cv_cc_nomfi_needed=yes]) + CXXFLAGS="$gl_save_CXXFLAGS" + ]) + AC_MSG_RESULT([$gl_cv_cc_nomfi_needed]) + fi + + dnl Next, check if -Werror -Wuninitialized is useful with the + dnl user's choice of $CXXFLAGS; some versions of gcc warn that it + dnl has no effect if -O is not also used + AC_MSG_CHECKING([whether -Wuninitialized is supported]) + AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [ + gl_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS -Werror -Wuninitialized" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[]], [[]])], + [gl_cv_cc_uninitialized_supported=yes], + [gl_cv_cc_uninitialized_supported=no]) + CXXFLAGS="$gl_save_CXXFLAGS"]) + AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported]) + + fi + + # List all gcc warning categories. + # To compare this list to your installed GCC's, run this Bash command: + # + # comm -3 \ + # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings-cxx.m4 | sort) \ + # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort | + # grep -v -x -f <( + # awk '/^[^#]/ {print $1}' ../build-aux/g++-warning.spec)) + + gl_manywarn_set= + for gl_manywarn_item in \ + -W \ + -Wabi \ + -Wabi-tag \ + -Waddress \ + -Waggressive-loop-optimizations \ + -Wall \ + -Wattributes \ + -Wbool-compare \ + -Wbuiltin-macro-redefined \ + -Wcast-align \ + -Wchar-subscripts \ + -Wchkp \ + -Wclobbered \ + -Wcomment \ + -Wcomments \ + -Wconditionally-supported \ + -Wconversion-null \ + -Wcoverage-mismatch \ + -Wcpp \ + -Wctor-dtor-privacy \ + -Wdate-time \ + -Wdelete-incomplete \ + -Wdelete-non-virtual-dtor \ + -Wdeprecated \ + -Wdeprecated-declarations \ + -Wdisabled-optimization \ + -Wdiv-by-zero \ + -Wdouble-promotion \ + -Weffc++ \ + -Wempty-body \ + -Wendif-labels \ + -Wenum-compare \ + -Wextra \ + -Wformat-contains-nul \ + -Wformat-extra-args \ + -Wformat-nonliteral \ + -Wformat-security \ + -Wformat-signedness \ + -Wformat-y2k \ + -Wformat-zero-length \ + -Wfree-nonheap-object \ + -Wignored-qualifiers \ + -Winherited-variadic-ctor \ + -Winit-self \ + -Winline \ + -Wint-to-pointer-cast \ + -Winvalid-memory-model \ + -Winvalid-offsetof \ + -Winvalid-pch \ + -Wliteral-suffix \ + -Wlogical-not-parentheses \ + -Wlogical-op \ + -Wmain \ + -Wmaybe-uninitialized \ + -Wmemset-transposed-args \ + -Wmissing-braces \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-include-dirs \ + -Wmultichar \ + -Wnarrowing \ + -Wnoexcept \ + -Wnon-template-friend \ + -Wnon-virtual-dtor \ + -Wnonnull \ + -Wodr \ + -Wold-style-cast \ + -Wopenmp-simd \ + -Woverflow \ + -Woverlength-strings \ + -Woverloaded-virtual \ + -Wpacked \ + -Wpacked-bitfield-compat \ + -Wparentheses \ + -Wpmf-conversions \ + -Wpointer-arith \ + -Wpragmas \ + -Wreorder \ + -Wreturn-local-addr \ + -Wreturn-type \ + -Wsequence-point \ + -Wshadow \ + -Wshift-count-negative \ + -Wshift-count-overflow \ + -Wsign-promo \ + -Wsized-deallocation \ + -Wsizeof-array-argument \ + -Wsizeof-pointer-memaccess \ + -Wstack-protector \ + -Wstrict-aliasing \ + -Wstrict-null-sentinel \ + -Wstrict-overflow \ + -Wsuggest-attribute=const \ + -Wsuggest-attribute=format \ + -Wsuggest-attribute=noreturn \ + -Wsuggest-attribute=pure \ + -Wsuggest-final-methods \ + -Wsuggest-final-types \ + -Wsuggest-override \ + -Wswitch \ + -Wswitch-bool \ + -Wswitch-default \ + -Wsync-nand \ + -Wsystem-headers \ + -Wtrampolines \ + -Wtrigraphs \ + -Wtype-limits \ + -Wuninitialized \ + -Wunknown-pragmas \ + -Wunsafe-loop-optimizations \ + -Wunused \ + -Wunused-but-set-parameter \ + -Wunused-but-set-variable \ + -Wunused-function \ + -Wunused-label \ + -Wunused-local-typedefs \ + -Wunused-macros \ + -Wunused-parameter \ + -Wunused-result \ + -Wunused-value \ + -Wunused-variable \ + -Wuseless-cast \ + -Wvarargs \ + -Wvariadic-macros \ + -Wvector-operation-performance \ + -Wvirtual-move-assign \ + -Wvla \ + -Wvolatile-register-var \ + -Wwrite-strings \ + -Wzero-as-null-pointer-constant \ + \ + ; do + gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item" + done + + # gcc --help=warnings outputs an unusual form for these options; list + # them here so that the above 'comm' command doesn't report a false match. + gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2" + gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc" + gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2" + gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2" + + # These are needed for older GCC versions. + if test -n "$GXX"; then + case `($CXX --version) 2>/dev/null` in + 'g++ (GCC) '[[0-3]].* | \ + 'g++ (GCC) '4.[[0-7]].*) + gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option" + gl_manywarn_set="$gl_manywarn_set -funit-at-a-time" + ;; + esac + fi + + # Disable specific options as needed. + if test "$gl_cv_cc_nomfi_needed" = yes; then + gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers" + fi + + if test "$gl_cv_cc_uninitialized_supported" = no; then + gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized" + fi + + $1=$gl_manywarn_set +]) + +# gl_CXX_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS], +# [PROGRAM = AC_LANG_PROGRAM()]) +# --------------------------------------------- +# Adds parameter to WARN_CXXFLAGS if the compiler supports it when +# compiling PROGRAM. For example, gl_CXX_WARN_ADD([-Wparentheses]). +# +# If VARIABLE is a variable name, AC_SUBST it. +AC_DEFUN([gl_CXX_WARN_ADD], +[AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS]) +gl_COMPILER_OPTION_IF([$1], + [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_CXXFLAGS]], [[$2]]), [" $1"])], + [], + [$3]) +m4_ifval([$2], + [AS_LITERAL_IF([$2], [AC_SUBST([$2])])], + [AC_SUBST([WARN_CXXFLAGS])])dnl +]) diff --git a/gl/modules/manywarnings-cxx b/gl/modules/manywarnings-cxx new file mode 100644 index 0000000..cf7acf5 --- /dev/null +++ b/gl/modules/manywarnings-cxx @@ -0,0 +1,16 @@ +Description: +Helper M4 functions to help work out a set of warning parameters to use. + +Files: +m4/manywarnings-cxx.m4 + +Depends-on: +warnings + +configure.ac: + +License: +unlimited + +Maintainer: +Simon Josefsson diff --git a/m4/.gitignore b/m4/.gitignore index 90a122e..b81f2a1 100644 --- a/m4/.gitignore +++ b/m4/.gitignore @@ -35,3 +35,6 @@ /wchar_t.m4 /wint_t.m4 /ssize_t.m4 +/manywarnings.m4 +/warnings.m4 +/manywarnings-cxx.m4 diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4 index 0b32dda..89efb36 100644 --- a/m4/gnulib-cache.m4 +++ b/m4/gnulib-cache.m4 @@ -27,13 +27,16 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --local-dir=gl --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=gl bootstrap flock +# gnulib-tool --import --local-dir=gl --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-conditional-dependencies --libtool --macro-prefix=gl bootstrap flock manywarnings manywarnings-cxx snippet/unused-parameter # Specification in the form of a few gnulib-tool.m4 macro invocations: gl_LOCAL_DIR([gl]) gl_MODULES([ bootstrap flock + manywarnings + manywarnings-cxx + snippet/unused-parameter ]) gl_AVOID([]) gl_SOURCE_BASE([lib]) diff --git a/src/Makefile.am b/src/Makefile.am index fb8f0c5..0d2f32b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS=. aspell ispell uspell myspell hspell applespell voikko zemberek -AM_CPPFLAGS=-I$(top_srcdir) $(ENCHANT_CFLAGS) $(CC_WARN_CFLAGS) +AM_CPPFLAGS = -I$(top_srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib $(ENCHANT_CFLAGS) $(WARN_CFLAGS) lib_LTLIBRARIES = libenchant.la diff --git a/src/aspell/Makefile.am b/src/aspell/Makefile.am index 18bfcf1..5e54d1d 100644 --- a/src/aspell/Makefile.am +++ b/src/aspell/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(CC_WARN_CFLAGS) @ASPELL_INC@ -D_ENCHANT_BUILD=1 @ASPELL_CFLAGS@ +AM_CPPFLAGS = -I$(top_srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib -I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(WARN_CFLAGS) @ASPELL_INC@ -D_ENCHANT_BUILD=1 @ASPELL_CFLAGS@ aspell_LTLIBRARIES = $(target_lib) aspelldir= $(libdir)/enchant diff --git a/src/aspell/aspell_provider.c b/src/aspell/aspell_provider.c index 9a448b9..03bd1b9 100644 --- a/src/aspell/aspell_provider.c +++ b/src/aspell/aspell_provider.c @@ -28,6 +28,8 @@ * do so, delete this exception statement from your version. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -37,6 +39,7 @@ #include "enchant.h" #include "enchant-provider.h" +#include "unused-parameter.h" ENCHANT_PLUGIN_DECLARE("Aspell") @@ -150,7 +153,7 @@ aspell_dict_store_replacement (EnchantDict * me, } static EnchantDict * -aspell_provider_request_dict (EnchantProvider * me, const char *const tag) +aspell_provider_request_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, const char *const tag) { EnchantDict *dict; AspellSpeller *manager; @@ -183,7 +186,7 @@ aspell_provider_request_dict (EnchantProvider * me, const char *const tag) } static void -aspell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) +aspell_provider_dispose_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, EnchantDict * dict) { AspellSpeller *manager; @@ -194,7 +197,7 @@ aspell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) } static char ** -aspell_provider_list_dicts (EnchantProvider * me, +aspell_provider_list_dicts (EnchantProvider * me _GL_UNUSED_PARAMETER, size_t * out_n_dicts) { AspellConfig * spell_config; @@ -235,7 +238,7 @@ aspell_provider_list_dicts (EnchantProvider * me, } static void -aspell_provider_free_string_list (EnchantProvider * me, char **str_list) +aspell_provider_free_string_list (EnchantProvider * me _GL_UNUSED_PARAMETER, char **str_list) { g_strfreev (str_list); } @@ -247,13 +250,13 @@ aspell_provider_dispose (EnchantProvider * me) } static const char * -aspell_provider_identify (EnchantProvider * me) +aspell_provider_identify (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "aspell"; } static const char * -aspell_provider_describe (EnchantProvider * me) +aspell_provider_describe (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "Aspell Provider"; } diff --git a/src/enchant-lsmod.c b/src/enchant-lsmod.c index 6ed3f4f..05d56bc 100644 --- a/src/enchant-lsmod.c +++ b/src/enchant-lsmod.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "unused-parameter.h" #include "enchant.h" #include "enchant-provider.h" @@ -41,8 +42,8 @@ static void describe_dict (const char * const lang_tag, const char * const provider_name, - const char * const provider_desc, - const char * const provider_file, + const char * const provider_desc _GL_UNUSED_PARAMETER, + const char * const provider_file _GL_UNUSED_PARAMETER, void * user_data) { FILE * out = (FILE *)user_data; @@ -52,7 +53,7 @@ describe_dict (const char * const lang_tag, static void enumerate_providers (const char * name, const char * desc, - const char * file, + const char * file _GL_UNUSED_PARAMETER, void * user_data) { FILE * out = (FILE *)user_data; @@ -62,8 +63,8 @@ enumerate_providers (const char * name, static void enumerate_dicts (const char * const lang_tag, const char * const provider_name, - const char * const provider_desc, - const char * const provider_file, + const char * const provider_desc _GL_UNUSED_PARAMETER, + const char * const provider_file _GL_UNUSED_PARAMETER, void * user_data) { FILE * out = (FILE *)user_data; diff --git a/src/enchant.c b/src/enchant.c index 9c59ba2..98756bc 100644 --- a/src/enchant.c +++ b/src/enchant.c @@ -28,6 +28,8 @@ * do so, delete this exception statement from your version. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -41,6 +43,7 @@ #include "enchant.h" #include "enchant-provider.h" #include "pwl.h" +#include "unused-parameter.h" #if defined(__APPLE__) && defined(__MACH__) #define ENCHANT_USER_PATH_EXTENSION "Library", "Application Support", "Enchant" @@ -314,7 +317,7 @@ enchant_ascii_strdown (gchar *str, /* returns TRUE if tag is valid * for requires alphanumeric ASCII or underscore */ -static int +static _GL_ATTRIBUTE_PURE int enchant_is_valid_dictionary_tag(const char * const tag) { const char * it; @@ -670,11 +673,7 @@ enchant_dict_check (EnchantDict * dict, const char *const word, ssize_t len) * returns the number of items in @suggs after merge is complete */ static int -enchant_dict_merge_suggestions(EnchantDict * dict, - char ** suggs, - size_t n_suggs, - char ** new_suggs, - size_t n_new_suggs) +enchant_dict_merge_suggestions(char ** suggs, size_t n_suggs, char ** new_suggs, size_t n_new_suggs) { size_t i, j; @@ -809,13 +808,11 @@ enchant_dict_suggest (EnchantDict * dict, const char *const word, suggs = g_new0 (char *, n_suggs + 1); /* Copy over suggestions from dict, if no dupes */ - n_suggs = enchant_dict_merge_suggestions(dict, - suggs, 0, + n_suggs = enchant_dict_merge_suggestions(suggs, 0, dict_suggs, n_dict_suggs); /* Copy over suggestions from pwl, if no dupes */ - n_suggs = enchant_dict_merge_suggestions(dict, - suggs, n_suggs, + n_suggs = enchant_dict_merge_suggestions(suggs, n_suggs, pwl_suggs, n_pwl_suggs); if(n_suggs == 0) { @@ -1179,7 +1176,7 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name) { GModule *module = NULL; GDir *dir; - G_CONST_RETURN char *dir_entry; + const char *dir_entry; size_t entry_len, g_module_suffix_len; char * filename; @@ -1423,7 +1420,7 @@ enchant_dict_destroyed (gpointer data) } static void -enchant_provider_free (gpointer data, gpointer user_data) +enchant_provider_free (gpointer data, gpointer user_data _GL_UNUSED_PARAMETER) { EnchantProvider *provider; GModule *module; @@ -2088,7 +2085,7 @@ enchant_get_dirs_from_param (EnchantBroker * broker, const char * const param_na return _enchant_get_dirs_from_string (param_value); } -ENCHANT_MODULE_EXPORT(const char *) +ENCHANT_MODULE_EXPORT(const char *) _GL_ATTRIBUTE_CONST enchant_get_version (void) { return ENCHANT_VERSION_STRING; } diff --git a/src/hspell/Makefile.am b/src/hspell/Makefile.am index 28560c3..1d11782 100644 --- a/src/hspell/Makefile.am +++ b/src/hspell/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(CC_WARN_CFLAGS) $(HSPELL_CFLAGS) -D_ENCHANT_BUILD=1 +AM_CPPFLAGS = -I$(top_srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib -I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(WARN_CFLAGS) $(HSPELL_CFLAGS) -D_ENCHANT_BUILD=1 hspell_LTLIBRARIES = $(target_lib) hspelldir= $(libdir)/enchant diff --git a/src/hspell/hspell_provider.c b/src/hspell/hspell_provider.c index 99e7287..bd52aff 100644 --- a/src/hspell/hspell_provider.c +++ b/src/hspell/hspell_provider.c @@ -29,6 +29,8 @@ * do so, delete this exception statement from your version. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -38,6 +40,7 @@ #include "enchant.h" #include "enchant-provider.h" +#include "unused-parameter.h" ENCHANT_PLUGIN_DECLARE ("Hspell") @@ -205,7 +208,7 @@ hspell_provider_request_dict (EnchantProvider * me, const char *const tag) } static void -hspell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) +hspell_provider_dispose_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, EnchantDict * dict) { struct dict_radix *hspell_dict; @@ -217,7 +220,7 @@ hspell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) /* test for the existence of, then return $prefix/share/hspell/hebrew.wgz */ static char ** -hspell_provider_list_dicts (EnchantProvider * me, +hspell_provider_list_dicts (EnchantProvider * me _GL_UNUSED_PARAMETER, size_t * out_n_dicts) { const char * dictionary_path; @@ -246,7 +249,7 @@ hspell_provider_dictionary_exists (struct str_enchant_provider * me, } static void -hspell_provider_free_string_list (EnchantProvider * me, char **str_list) +hspell_provider_free_string_list (EnchantProvider * me _GL_UNUSED_PARAMETER, char **str_list) { g_strfreev (str_list); } @@ -258,13 +261,13 @@ hspell_provider_dispose (EnchantProvider * me) } static const char * -hspell_provider_identify (EnchantProvider * me) +hspell_provider_identify (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "hspell"; } static const char * -hspell_provider_describe (EnchantProvider * me) +hspell_provider_describe (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "Hspell Provider"; } diff --git a/src/ispell/Makefile.am b/src/ispell/Makefile.am index da20b6d..b62649c 100644 --- a/src/ispell/Makefile.am +++ b/src/ispell/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(CXX_WARN_CFLAGS) $(ISPELL_CFLAGS) -D_ENCHANT_BUILD=1 +AM_CPPFLAGS = -I$(top_srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib -I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(WARN_CXXFLAGS) $(ISPELL_CFLAGS) -D_ENCHANT_BUILD=1 ispell_LTLIBRARIES = $(target_lib) ispelldir= $(libdir)/enchant diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp index fcc9dd4..41b9eb2 100644 --- a/src/ispell/ispell_checker.cpp +++ b/src/ispell/ispell_checker.cpp @@ -1,4 +1,6 @@ /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -10,6 +12,7 @@ #include "sp_spell.h" #include "ispell_checker.h" #include "enchant.h" +#include "unused-parameter.h" #ifndef ENCHANT_ISPELL_HOME_DIR #define ENCHANT_ISPELL_HOME_DIR "ispell" @@ -67,6 +70,12 @@ static const IspellMap ispell_map [] = { static const size_t size_ispell_map = G_N_ELEMENTS(ispell_map); +static void +ispell_checker_free_helper (gpointer p, gpointer user _GL_UNUSED_PARAMETER) +{ + g_free (p); +} + static bool g_iconv_is_valid(GIConv i) { @@ -99,16 +108,39 @@ ISpellChecker::ISpellChecker(EnchantBroker * broker) m_nd(NULL), m_so(NULL), m_se(NULL), + m_sg(0), m_ti(NULL), m_te(NULL), + m_li(0), + m_co(0), + m_numhits(0), m_hashstrings(NULL), + m_hashheader({}), m_hashtbl(NULL), + m_hashsize(0), + m_aflag(0), + m_cflag(0), + m_lflag(0), + m_incfileflag(0), + m_nodictflag(0), + m_uerasechar(0), + m_ukillchar(0), + m_laststringch(0U), + m_defdupchar(0), + m_numpflags(0), + m_numsflags(0), m_pflaglist(NULL), m_sflaglist(NULL), m_chartypes(NULL), m_infile(NULL), m_outfile(NULL), m_askfilename(NULL), + m_changes(0), + m_readonly(0), + m_quit(0), + m_pcount(0), + m_maxposslen(0), + m_easypossibilities(0), m_Trynum(0), m_translate_in(G_ICONV_INVALID), m_translate_out(G_ICONV_INVALID) @@ -168,7 +200,7 @@ ISpellChecker::checkWord(const char * const utf8Word, size_t length) len_out = sizeof( szWord ) - 1; result = g_iconv(m_translate_in, &In, &len_in, &Out, &len_out); g_free(normalizedWord); - if ((size_t)-1 == result) + if (static_cast<size_t>(-1) == result) return false; *Out = '\0'; } @@ -215,7 +247,7 @@ ISpellChecker::suggestWord(const char * const utf8Word, size_t length, len_out = sizeof( word8 ) - 1; result = g_iconv(m_translate_in, &In, &len_in, &Out, &len_out); g_free(normalizedWord); - if ((size_t)-1 == result) + if (static_cast<size_t>(-1) == result) return NULL; *Out = '\0'; } @@ -250,11 +282,11 @@ ISpellChecker::suggestWord(const char * const utf8Word, size_t length, size_t len_in, len_out; char *In = m_possibilities[c]; - char *Out = reinterpret_cast<char *>(utf8Sugg); + char *Out = utf8Sugg; len_in = l; len_out = INPUTWORDLEN + MAXAFFIXLEN; - if ((size_t)-1 == g_iconv(m_translate_out, &In, &len_in, &Out, &len_out)) { + if (static_cast<size_t>(-1) == g_iconv(m_translate_out, &In, &len_in, &Out, &len_out)) { *out_n_suggestions = c; return sugg_arr; } @@ -280,11 +312,11 @@ ispell_checker_get_dictionary_dirs (EnchantBroker * broker) for (iter = config_dirs; iter; iter = iter->next) { - dirs = g_slist_append (dirs, g_build_filename ((const gchar *)iter->data, - ENCHANT_ISPELL_HOME_DIR, NULL)); + dirs = g_slist_append (dirs, g_build_filename (static_cast<const gchar *>(iter->data), + ENCHANT_ISPELL_HOME_DIR, nullptr)); } - g_slist_foreach (config_dirs, (GFunc)g_free, NULL); + g_slist_foreach (config_dirs, ispell_checker_free_helper, nullptr); g_slist_free (config_dirs); } @@ -292,7 +324,7 @@ ispell_checker_get_dictionary_dirs (EnchantBroker * broker) char * enchant_prefix = enchant_get_prefix_dir(); if(enchant_prefix) { - char * ispell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "ispell", NULL); + char * ispell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "ispell", nullptr); g_free(enchant_prefix); dirs = g_slist_append (dirs, ispell_prefix); } @@ -308,10 +340,10 @@ ispell_checker_get_dictionary_dirs (EnchantBroker * broker) for (iter = config_dirs; iter; iter = iter->next) { - dirs = g_slist_append (dirs, g_strdup ((const gchar *)iter->data)); + dirs = g_slist_append (dirs, g_strdup (static_cast<const gchar *>(iter->data))); } - g_slist_foreach (config_dirs, (GFunc)g_free, NULL); + g_slist_foreach (config_dirs, ispell_checker_free_helper, nullptr); g_slist_free (config_dirs); } @@ -330,12 +362,12 @@ s_buildHashNames (std::vector<std::string> & names, EnchantBroker * broker, cons { char *tmp; - tmp = g_build_filename ((const gchar *)iter->data, dict, NULL); + tmp = g_build_filename (static_cast<const gchar *>(iter->data), dict, nullptr); names.push_back (tmp); g_free (tmp); } - g_slist_foreach (dirs, (GFunc)g_free, NULL); + g_slist_foreach (dirs, ispell_checker_free_helper, nullptr); g_slist_free (dirs); } @@ -371,7 +403,7 @@ ISpellChecker::loadDictionaryForLanguage ( const char * szLang ) for (size_t i = 0; i < size_ispell_map; i++) { - const IspellMap * mapping = (const IspellMap *)(&(ispell_map[i])); + const IspellMap * mapping = &(ispell_map[i]); if (!strcmp (szLang, mapping->lang)) { szFile = mapping->dict; @@ -389,14 +421,14 @@ ISpellChecker::loadDictionaryForLanguage ( const char * szLang ) return false; // one of the two above calls succeeded - setDictionaryEncoding (hashname, encoding); + setDictionaryEncoding (encoding); g_free (hashname); return true; } void -ISpellChecker::setDictionaryEncoding( const char * hashname, const char * encoding ) +ISpellChecker::setDictionaryEncoding( const char * encoding ) { /* Get Hash encoding from XML file. This should always work! */ try_autodetect_charset(encoding); @@ -405,7 +437,7 @@ ISpellChecker::setDictionaryEncoding( const char * hashname, const char * encodi { /* We still have to setup prefstringchar*/ prefstringchar = findfiletype("utf8", 1, deftflag < 0 ? &deftflag - : static_cast<int *>(NULL)); + : nullptr); if (prefstringchar < 0) { @@ -414,7 +446,7 @@ ISpellChecker::setDictionaryEncoding( const char * hashname, const char * encodi { sprintf(teststring, "latin%d", n1); prefstringchar = findfiletype(teststring, 1, - deftflag < 0 ? &deftflag : static_cast<int *>(NULL)); + deftflag < 0 ? &deftflag : nullptr); if (prefstringchar >= 0) break; } @@ -424,7 +456,7 @@ ISpellChecker::setDictionaryEncoding( const char * hashname, const char * encodi } /* Test for UTF-8 first */ - prefstringchar = findfiletype("utf8", 1, deftflag < 0 ? &deftflag : static_cast<int *>(NULL)); + prefstringchar = findfiletype("utf8", 1, deftflag < 0 ? &deftflag : nullptr); if (prefstringchar >= 0) { m_translate_in = g_iconv_open("UTF-8", "UTF-8"); @@ -438,11 +470,11 @@ ISpellChecker::setDictionaryEncoding( const char * hashname, const char * encodi if (!g_iconv_is_valid(m_translate_in)) { /* Look for "altstringtype" names from latin1 to latin15 */ - for(int n1 = 1; n1 <= 15; n1++) + for(unsigned n1 = 1; n1 <= 15; n1++) { char * teststring = g_strdup_printf("latin%u", n1); prefstringchar = findfiletype(teststring, 1, - deftflag < 0 ? &deftflag : static_cast<int *>(NULL)); + deftflag < 0 ? &deftflag : nullptr); if (prefstringchar >= 0) { m_translate_in = g_iconv_open(teststring, "UTF-8"); @@ -474,7 +506,7 @@ ISpellChecker::requestDictionary(const char *szLang) std::string shortened_dict (szLang); size_t uscore_pos; - if ((uscore_pos = shortened_dict.rfind ('_')) != ((size_t)-1)) { + if ((uscore_pos = shortened_dict.rfind ('_')) != (static_cast<size_t>(-1))) { shortened_dict = shortened_dict.substr(0, uscore_pos); if (!loadDictionaryForLanguage (shortened_dict.c_str())) return false; @@ -498,7 +530,7 @@ ispell_dict_suggest (EnchantDict * me, const char *const word, { ISpellChecker * checker; - checker = (ISpellChecker *) me->user_data; + checker = static_cast<ISpellChecker *>(me->user_data); return checker->suggestWord (word, len, out_n_suggs); } @@ -507,7 +539,7 @@ ispell_dict_check (EnchantDict * me, const char *const word, size_t len) { ISpellChecker * checker; - checker = (ISpellChecker *) me->user_data; + checker = static_cast<ISpellChecker *>(me->user_data); if (checker->checkWord(word, len)) return 0; @@ -534,7 +566,7 @@ ispell_provider_request_dict (EnchantProvider * me, const char *const tag) } dict = g_new0 (EnchantDict, 1); - dict->user_data = (void *) checker; + dict->user_data = checker; dict->check = ispell_dict_check; dict->suggest = ispell_dict_suggest; // don't implement session or personal @@ -543,11 +575,11 @@ ispell_provider_request_dict (EnchantProvider * me, const char *const tag) } static void -ispell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) +ispell_provider_dispose_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, EnchantDict * dict) { ISpellChecker * checker; - checker = (ISpellChecker *) dict->user_data; + checker = static_cast<ISpellChecker *>(dict->user_data); delete checker; g_free (dict); @@ -589,7 +621,7 @@ ispell_provider_list_dictionaries (EnchantProvider * me, *out_n_dicts = nb; if (nb == 0) { g_free (out_dicts); - out_dicts = NULL; + out_dicts = nullptr; } return out_dicts; @@ -606,7 +638,7 @@ ispell_provider_dictionary_exists (struct str_enchant_provider * me, for (size_t i = 0; i < size_ispell_map; i++) { - const IspellMap * mapping = (const IspellMap *)(&(ispell_map[i])); + const IspellMap * mapping = &(ispell_map[i]); if (!strcmp (tag, mapping->lang) || !strcmp (shortened_dict.c_str(), mapping->lang)) return _ispell_provider_dictionary_exists(me->owner, mapping->dict); } @@ -615,7 +647,7 @@ ispell_provider_dictionary_exists (struct str_enchant_provider * me, } static void -ispell_provider_free_string_list (EnchantProvider * me, char **str_list) +ispell_provider_free_string_list (EnchantProvider * me _GL_UNUSED_PARAMETER, char **str_list) { g_strfreev (str_list); } @@ -627,13 +659,13 @@ ispell_provider_dispose (EnchantProvider * me) } static const char * -ispell_provider_identify (EnchantProvider * me) +ispell_provider_identify (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "ispell"; } static const char * -ispell_provider_describe (EnchantProvider * me) +ispell_provider_describe (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "Ispell Provider"; } diff --git a/src/ispell/ispell_checker.h b/src/ispell/ispell_checker.h index 8ffcc31..af4acda 100644 --- a/src/ispell/ispell_checker.h +++ b/src/ispell/ispell_checker.h @@ -26,7 +26,7 @@ private: char * loadDictionary (const char * szLang ); bool loadDictionaryForLanguage ( const char * szLang ); - void setDictionaryEncoding ( const char * hashname, const char * enc ); + void setDictionaryEncoding ( const char * enc ); // // The member functions after this point were formerly global functions diff --git a/src/myspell/Makefile.am b/src/myspell/Makefile.am index f278a37..cfea67b 100644 --- a/src/myspell/Makefile.am +++ b/src/myspell/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(MYSPELL_CFLAGS) $(CXX_WARN_CFLAGS) -D_ENCHANT_BUILD=1 +AM_CPPFLAGS = -I$(top_srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib -I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(MYSPELL_CFLAGS) $(WARN_CXXFLAGS) -D_ENCHANT_BUILD=1 myspell_LTLIBRARIES = $(target_lib) myspelldir= $(libdir)/enchant diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp index d04a726..8f4f128 100644 --- a/src/myspell/myspell_checker.cpp +++ b/src/myspell/myspell_checker.cpp @@ -28,6 +28,8 @@ * do so, delete this exception statement from your version. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -37,6 +39,7 @@ #include "enchant.h" #include "enchant-provider.h" +#include "unused-parameter.h" #include <hunspell/hunspell.hxx> @@ -72,6 +75,12 @@ private: EnchantBroker *m_broker; }; +static void +myspell_checker_free_helper (gpointer p, gpointer user _GL_UNUSED_PARAMETER) +{ + g_free (p); +} + /***************************************************************************/ static bool @@ -109,7 +118,7 @@ MySpellChecker::checkWord(const char *utf8Word, size_t len) size_t len_out = sizeof( word8 ) - 1; size_t result = g_iconv(m_translate_in, &in, &len_in, &out, &len_out); g_free(normalizedWord); - if ((size_t)-1 == result) + if (static_cast<size_t>(-1) == result) return false; *out = '\0'; if (myspell->spell(word8)) @@ -124,7 +133,7 @@ MySpellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug if (len > MAXWORDLEN || !g_iconv_is_valid(m_translate_in) || !g_iconv_is_valid(m_translate_out)) - return 0; + return nullptr; // the 8bit encodings use precomposed forms char *normalizedWord = g_utf8_normalize (utf8Word, len, G_NORMALIZE_NFC); @@ -135,8 +144,8 @@ MySpellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug size_t len_out = sizeof(word8) - 1; size_t result = g_iconv(m_translate_in, &in, &len_in, &out, &len_out); g_free(normalizedWord); - if ((size_t)-1 == result) - return NULL; + if (static_cast<size_t>(-1) == result) + return nullptr; *out = '\0'; char **sugMS; @@ -148,8 +157,8 @@ MySpellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug len_in = strlen(in); len_out = MAXWORDLEN; char *word = g_new0(char, len_out + 1); - out = reinterpret_cast<char *>(word); - if ((size_t)-1 == g_iconv(m_translate_out, &in, &len_in, &out, &len_out)) { + out = word; + if (static_cast<size_t>(-1) == g_iconv(m_translate_out, &in, &len_in, &out, &len_out)) { for (size_t j = i; j < *nsug; j++) free(sugMS[j]); free(sugMS); @@ -165,7 +174,7 @@ MySpellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsug return sug; } else - return 0; + return nullptr; } static GSList * @@ -180,11 +189,11 @@ myspell_checker_get_dictionary_dirs (EnchantBroker * broker) for (iter = config_dirs; iter; iter = iter->next) { - dirs = g_slist_append (dirs, g_build_filename ((const gchar *)iter->data, - "myspell", NULL)); + dirs = g_slist_append (dirs, g_build_filename (static_cast<const gchar *>(iter->data), + "myspell", nullptr)); } - g_slist_foreach (config_dirs, (GFunc)g_free, NULL); + g_slist_foreach (config_dirs, myspell_checker_free_helper, nullptr); g_slist_free (config_dirs); } @@ -194,7 +203,7 @@ myspell_checker_get_dictionary_dirs (EnchantBroker * broker) for (iter = system_data_dirs; *iter; iter++) { - dirs = g_slist_append (dirs, g_build_filename (*iter, "myspell", "dicts", NULL)); + dirs = g_slist_append (dirs, g_build_filename (*iter, "myspell", "dicts", nullptr)); } } @@ -202,7 +211,7 @@ myspell_checker_get_dictionary_dirs (EnchantBroker * broker) char * enchant_prefix = enchant_get_prefix_dir(); if(enchant_prefix) { - char * myspell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "myspell", NULL); + char * myspell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "myspell", nullptr); g_free(enchant_prefix); dirs = g_slist_append (dirs, myspell_prefix); } @@ -218,10 +227,10 @@ myspell_checker_get_dictionary_dirs (EnchantBroker * broker) for (iter = config_dirs; iter; iter = iter->next) { - dirs = g_slist_append (dirs, g_strdup ((const gchar *)iter->data)); + dirs = g_slist_append (dirs, g_strdup (static_cast<const gchar *>(iter->data))); } - g_slist_foreach (config_dirs, (GFunc)g_free, NULL); + g_slist_foreach (config_dirs, myspell_checker_free_helper, nullptr); g_slist_free (config_dirs); } @@ -246,10 +255,10 @@ s_buildDictionaryDirs (std::vector<std::string> & dirs, EnchantBroker * broker) myspell_dirs = myspell_checker_get_dictionary_dirs (broker); for (iter = myspell_dirs; iter; iter = iter->next) { - dirs.push_back ((const char *)iter->data); + dirs.push_back (static_cast<const char *>(iter->data)); } - g_slist_foreach (myspell_dirs, (GFunc)g_free, NULL); + g_slist_foreach (myspell_dirs, myspell_checker_free_helper, nullptr); g_slist_free (myspell_dirs); } @@ -261,10 +270,10 @@ s_buildHashNames (std::vector<std::string> & names, EnchantBroker * broker, cons std::vector<std::string> dirs; s_buildDictionaryDirs (dirs, broker); - char *dict_dic = g_strconcat(dict, ".dic", NULL); + char *dict_dic = g_strconcat(dict, ".dic", nullptr); for (size_t i = 0; i < dirs.size(); i++) { - char *tmp = g_build_filename (dirs[i].c_str(), dict_dic, NULL); + char *tmp = g_build_filename (dirs[i].c_str(), dict_dic, nullptr); names.push_back (tmp); g_free (tmp); } @@ -320,13 +329,13 @@ myspell_request_dictionary (EnchantBroker * broker, const char * tag) s_buildDictionaryDirs (dirs, broker); for (size_t i = 0; i < dirs.size(); i++) { - GDir *dir = g_dir_open (dirs[i].c_str(), 0, NULL); + GDir *dir = g_dir_open (dirs[i].c_str(), 0, nullptr); if (dir) { const char *dir_entry; while ((dir_entry = g_dir_read_name (dir)) != NULL) { if (is_plausible_dict_for_tag(dir_entry, tag)) { char *dict = g_build_filename (dirs[i].c_str(), - dir_entry, NULL); + dir_entry, nullptr); if(s_hasCorrespondingAffFile(dict)){ g_dir_close (dir); return dict; @@ -380,7 +389,7 @@ myspell_dict_suggest (EnchantDict * me, const char *const word, { MySpellChecker * checker; - checker = (MySpellChecker *) me->user_data; + checker = static_cast<MySpellChecker *>(me->user_data); return checker->suggestWord (word, len, out_n_suggs); } @@ -389,7 +398,7 @@ myspell_dict_check (EnchantDict * me, const char *const word, size_t len) { MySpellChecker * checker; - checker = (MySpellChecker *) me->user_data; + checker = static_cast<MySpellChecker *>(me->user_data); if (checker->checkWord(word, len)) return 0; @@ -401,12 +410,12 @@ static void myspell_provider_enum_dicts (const char * const directory, std::vector<std::string> & out_dicts) { - GDir * dir = g_dir_open (directory, 0, NULL); + GDir * dir = g_dir_open (directory, 0, nullptr); if (dir) { const char * entry; while ((entry = g_dir_read_name (dir)) != NULL) { - char * utf8_entry = g_filename_to_utf8 (entry, -1, NULL, NULL, NULL); + char * utf8_entry = g_filename_to_utf8 (entry, -1, nullptr, nullptr, nullptr); if (utf8_entry) { std::string dir_entry (utf8_entry); g_free (utf8_entry); @@ -419,7 +428,7 @@ myspell_provider_enum_dicts (const char * const directory, { std::string name(dir_entry.substr (0, hit)); std::string affFileName(name + ".aff"); - char * aff = g_build_filename(directory, affFileName.c_str(), NULL); + char * aff = g_build_filename(directory, affFileName.c_str(), nullptr); if (g_file_test(aff, G_FILE_TEST_EXISTS)) { out_dicts.push_back (dir_entry.substr (0, hit)); @@ -465,7 +474,7 @@ myspell_provider_list_dicts (EnchantProvider * me, } static void -myspell_provider_free_string_list (EnchantProvider * me, char **str_list) +myspell_provider_free_string_list (EnchantProvider * me _GL_UNUSED_PARAMETER, char **str_list) { g_strfreev (str_list); } @@ -496,7 +505,7 @@ myspell_provider_request_dict(EnchantProvider * me, const char *const tag) } static void -myspell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) +myspell_provider_dispose_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, EnchantDict * dict) { MySpellChecker *checker; @@ -533,13 +542,13 @@ myspell_provider_dispose (EnchantProvider * me) } static const char * -myspell_provider_identify (EnchantProvider * me) +myspell_provider_identify (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "myspell"; } static const char * -myspell_provider_describe (EnchantProvider * me) +myspell_provider_describe (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "Myspell Provider"; } @@ -52,6 +52,8 @@ * */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -63,6 +65,7 @@ #include <glib.h> #include <glib/gstdio.h> #include "enchant-provider.h" +#include "unused-parameter.h" #include "pwl.h" @@ -758,7 +761,8 @@ static void enchant_pwl_suggest_cb(char* match,EnchantTrieMatcher* matcher) } -void enchant_pwl_free_string_list(EnchantPWL *pwl, char** string_list) +void enchant_pwl_free_string_list(EnchantPWL *pwl _GL_UNUSED_PARAMETER, + char** string_list) { g_strfreev(string_list); } @@ -794,7 +798,9 @@ static void enchant_trie_free(EnchantTrie* trie) g_free(trie); } -static void enchant_trie_free_cb(void* key, void* value, void* data) +static void enchant_trie_free_cb(void* key _GL_UNUSED_PARAMETER, + void* value, + void* data _GL_UNUSED_PARAMETER) { enchant_trie_free((EnchantTrie*) value); } diff --git a/src/uspell/Makefile.am b/src/uspell/Makefile.am index 8a42796..efe7d80 100644 --- a/src/uspell/Makefile.am +++ b/src/uspell/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(USPELL_CFLAGS) $(CXX_WARN_CFLAGS) -D_ENCHANT_BUILD=1 +AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(USPELL_CFLAGS) $(WARN_CXXFLAGS) -D_ENCHANT_BUILD=1 uspell_LTLIBRARIES = $(target_lib) uspelldir= $(libdir)/enchant diff --git a/src/voikko/Makefile.am b/src/voikko/Makefile.am index 739c36a..3e724ce 100644 --- a/src/voikko/Makefile.am +++ b/src/voikko/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(CC_WARN_CFLAGS) $(VOIKKO_CFLAGS) -D_ENCHANT_BUILD=1 +AM_CPPFLAGS = -I$(top_srcdir) $(ISYSTEM)$(top_builddir)/lib $(ISYSTEM)$(top_srcdir)/lib -I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(WARN_CFLAGS) $(VOIKKO_CFLAGS) -D_ENCHANT_BUILD=1 voikko_LTLIBRARIES = $(target_lib) voikkodir= $(libdir)/enchant diff --git a/src/voikko/voikko_provider.c b/src/voikko/voikko_provider.c index 6cf4c6d..d4a6327 100644 --- a/src/voikko/voikko_provider.c +++ b/src/voikko/voikko_provider.c @@ -30,12 +30,15 @@ * do so, delete this exception statement from your version. */ +#include "config.h" + #include <stdio.h> #include <stdlib.h> #include <string.h> #include <glib.h> #include <libvoikko/voikko.h> +#include "unused-parameter.h" #include "enchant.h" #include "enchant-provider.h" @@ -48,7 +51,7 @@ ENCHANT_PLUGIN_DECLARE("Voikko") static int -voikko_dict_check (EnchantDict * me, const char *const word, size_t len) +voikko_dict_check (EnchantDict * me, const char *const word, size_t len _GL_UNUSED_PARAMETER) { int result; int voikko_handle; @@ -65,7 +68,7 @@ voikko_dict_check (EnchantDict * me, const char *const word, size_t len) static char ** voikko_dict_suggest (EnchantDict * me, const char *const word, - size_t len, size_t * out_n_suggs) + size_t len _GL_UNUSED_PARAMETER, size_t * out_n_suggs) { char **sugg_arr; int voikko_handle; @@ -104,14 +107,14 @@ voikko_provider_request_dict (EnchantProvider * me, const char *const tag) } static void -voikko_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict) +voikko_provider_dispose_dict (EnchantProvider * me _GL_UNUSED_PARAMETER, EnchantDict * dict) { voikko_terminate((long) dict->user_data); g_free (dict); } static int -voikko_provider_dictionary_exists (struct str_enchant_provider * me, +voikko_provider_dictionary_exists (struct str_enchant_provider * me _GL_UNUSED_PARAMETER, const char *const tag) { int voikko_handle; @@ -130,7 +133,7 @@ voikko_provider_dictionary_exists (struct str_enchant_provider * me, static char ** -voikko_provider_list_dicts (EnchantProvider * me, +voikko_provider_list_dicts (EnchantProvider * me _GL_UNUSED_PARAMETER, size_t * out_n_dicts) { char ** out_list = NULL; @@ -148,7 +151,8 @@ voikko_provider_list_dicts (EnchantProvider * me, } static void -voikko_provider_free_string_list (EnchantProvider * me, char **str_list) +voikko_provider_free_string_list (EnchantProvider * me _GL_UNUSED_PARAMETER, + char **str_list) { g_strfreev (str_list); } @@ -160,13 +164,13 @@ voikko_provider_dispose (EnchantProvider * me) } static const char * -voikko_provider_identify (EnchantProvider * me) +voikko_provider_identify (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "voikko"; } static const char * -voikko_provider_describe (EnchantProvider * me) +voikko_provider_describe (EnchantProvider * me _GL_UNUSED_PARAMETER) { return "Voikko Provider"; } diff --git a/src/zemberek/Makefile.am b/src/zemberek/Makefile.am index 6e30006..c347a53 100644 --- a/src/zemberek/Makefile.am +++ b/src/zemberek/Makefile.am @@ -4,7 +4,7 @@ else target_lib = endif -AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(ZEMBEREK_CFLAGS) $(CXX_WARN_CFLAGS) -D_ENCHANT_BUILD=1 +AM_CPPFLAGS=-I$(top_srcdir)/src $(ENCHANT_CFLAGS) $(ZEMBEREK_CFLAGS) $(WARN_CXXFLAGS) -D_ENCHANT_BUILD=1 zemberek_LTLIBRARIES = $(target_lib) zemberekdir= $(libdir)/enchant |