From 7ba9ab7e4c7c8c0ae16529c79e9f578b5d79459b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 10 Mar 2018 11:22:10 +0100 Subject: [PATCH] Gtk library: Add configuration to avoid syntax error, add test file (#1109) Add configuration for G_UNLIKELY and G_LIKELY to avoid syntax errors when these macros are used as condition without enclosing brackets. Add test file to verify Gtk library configuration. Syntax check for the test file is only done when Gtk+2.0 or Gtk+3.0 is found and working. Tested on Cygwin and on Ubuntu 16.04. --- cfg/gtk.cfg | 2 ++ test/cfg/gtk.c | 22 ++++++++++++++++++++++ test/cfg/runtests.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 test/cfg/gtk.c diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 6724f716f..f298758ef 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -5,6 +5,8 @@ + + g_thread_new g_thread_try_new diff --git a/test/cfg/gtk.c b/test/cfg/gtk.c new file mode 100644 index 000000000..9ef0fd9e9 --- /dev/null +++ b/test/cfg/gtk.c @@ -0,0 +1,22 @@ + +// Test library configuration for gtk.cfg +// +// Usage: +// $ cppcheck --check-library --enable=information --inconclusive --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --library=gtk test/cfg/gtk.cpp +// => +// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0 +// + +#include + +void validCode(int argInt) +{ + // if G_UNLIKELY is not defined this results in a syntax error + if G_UNLIKELY(argInt == 1) { + } else if (G_UNLIKELY(argInt == 2)) { + } + + if G_LIKELY(argInt == 0) { + } else if (G_LIKELY(argInt == -1)) { + } +} diff --git a/test/cfg/runtests.sh b/test/cfg/runtests.sh index fa5348616..b86a11df5 100755 --- a/test/cfg/runtests.sh +++ b/test/cfg/runtests.sh @@ -64,3 +64,36 @@ else fi fi ${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=wxwidgets -f ${DIR}wxwidgets.cpp + +# gtk.c +set +e +pkg-config --version +PKGCONFIG_RETURNCODE=$? +set -e +if [ $PKGCONFIG_RETURNCODE -ne 0 ]; then + echo "pkg-config needed to retrieve GTK+ configuration is not available, skipping syntax check." +else + set +e + GTKCONFIG=$(pkg-config --cflags gtk+-3.0) + GTKCONFIG_RETURNCODE=$? + set -e + if [ $GTKCONFIG_RETURNCODE -ne 0 ]; then + set +e + GTKCONFIG=$(pkg-config --cflags gtk+-2.0) + GTKCONFIG_RETURNCODE=$? + set -e + fi + if [ $GTKCONFIG_RETURNCODE -eq 0 ]; then + set +e + echo -e "#include " | ${CC} ${CC_OPT} ${GTKCONFIG} -x c - + GTKCHECK_RETURNCODE=$? + set -e + if [ $GTKCHECK_RETURNCODE -ne 0 ]; then + echo "GTK+ not completely present or not working, skipping syntax check with ${CXX}." + else + echo "GTK+ found and working, checking syntax with ${CXX} now." + ${CC} ${CC_OPT} ${GTKCONFIG} ${DIR}gtk.c + fi + fi +fi +${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --library=gtk -f ${DIR}gtk.c