diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-04 20:41:25 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-04 20:41:30 +0200 |
commit | ff5075e7f149ffeb9934cb4a505660fc80a9c655 (patch) | |
tree | 73d524e70df16f11c7ff031280cfceb76d6de368 /src/include/gnunet_common.h | |
parent | 087337ed13af01c2016a6f084024de14d02a5851 (diff) |
do not generate tautological comparisson warnings for assertions (if gcc/clang version supports them)
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r-- | src/include/gnunet_common.h | 22 |
1 files changed, 20 insertions, 2 deletions
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 |