From ff5075e7f149ffeb9934cb4a505660fc80a9c655 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 4 Aug 2021 20:41:25 +0200 Subject: do not generate tautological comparisson warnings for assertions (if gcc/clang version supports them) --- src/include/gnunet_common.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/include/gnunet_common.h') diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index df1ccff26..8cfeab1cc 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2006-2020 GNUnet e.V. + Copyright (C) 2006-2021 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -875,10 +875,14 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); * @ingroup logging * Use this for fatal errors that cannot be handled */ +#if __GNUC__ >= 6 || __clang_major__ >= 6 #define GNUNET_assert(cond) \ do \ { \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wtautological-compare\"") \ if (! (cond)) \ + _Pragma("GCC diagnostic pop") \ { \ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ _ ("Assertion failed at %s:%d. Aborting.\n"), \ @@ -887,7 +891,21 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind); GNUNET_abort_ (); \ } \ } while (0) - +#else +/* older GCC/clangs do not support -Wtautological-compare */ +#define GNUNET_assert(cond) \ + do \ + { \ + if (! (cond)) \ + { \ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \ + _ ("Assertion failed at %s:%d. Aborting.\n"), \ + __FILE__, \ + __LINE__); \ + GNUNET_abort_ (); \ + } \ + } while (0) +#endif /** * @ingroup logging -- cgit v1.2.3