Skip to content

Commit

Permalink
feat: add HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI macro
Browse files Browse the repository at this point in the history
Due to the way HEDLEY_STATIC_ASSERT is implemented (I have regrets...),
it will sometimes get compiled to nothing but leave an extra semi-colon
dangling in the code, which some compilers will warn about.
  • Loading branch information
nemequ committed Sep 14, 2024
1 parent 806ad2a commit 9d193f2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
6 changes: 6 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 16
==========

* New HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI macro.
* Assorted bug fixes and enhancements.

Version 15
==========

Expand Down
17 changes: 17 additions & 0 deletions hedley.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,23 @@
# define HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
#endif

#if defined(HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI)
# undef HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI
#endif
#if HEDLEY_HAS_WARNING("-Wc++11-extra-semi") && HEDLEY_HAS_WARNING("-Wextra-semi")
# define HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI _Pragma("clang diagnostic ignored \"-Wc++11-extra-semi\"") _Pragma("clang diagnostic ignored \"-Wextra-semi\"")
#elif HEDLEY_HAS_WARNING("-Wextra-semi")
# define HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI _Pragma("clang diagnostic ignored \"-Wextra-semi\"")
#elif HEDLEY_IAR_VERSION_CHECK(8,0,0)
# define HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI _Pragma("diag_suppress=Pe381")
#elif defined(HEDLEY_SUNPRO_VERSION) && !defined(__cplusplus)
# define HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI _Pragma("error_messages(off,E_EMPTY_DECLARATION)")
#elif defined(HEDLEY_TI_VERSION)
# define HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI _Pragma("diag_suppress 383")
#else
# define HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI
#endif

#if defined(HEDLEY_DEPRECATED)
# undef HEDLEY_DEPRECATED
#endif
Expand Down
12 changes: 1 addition & 11 deletions test/empty-bases.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#include "../hedley.h"

#if HEDLEY_HAS_WARNING("-Wc++11-extra-semi")
# pragma clang diagnostic warning "-Wc++11-extra-semi"
#elif HEDLEY_HAS_WARNING("-Wextra-semi")
# pragma clang diagnostic warning "-Wextra-semi"
#elif HEDLEY_IAR_VERSION_CHECK(8,0,0)
# pragma diag_suppress=Pe381
#elif defined(HEDLEY_SUNPRO_VERSION) && !defined(__cplusplus)
# pragma error_messages(off,E_EMPTY_DECLARATION)
#elif defined(HEDLEY_TI_VERSION)
# pragma diag_suppress 383
#endif
HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI

#ifdef __cplusplus
struct Empty2 {};
Expand Down
10 changes: 1 addition & 9 deletions test/static-assert.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#include "../hedley.h"

#if HEDLEY_HAS_WARNING("-Wextra-semi")
# pragma clang diagnostic warning "-Wextra-semi"
#elif HEDLEY_IAR_VERSION_CHECK(8,0,0)
# pragma diag_suppress=Pe381
#elif defined(HEDLEY_SUNPRO_VERSION) && !defined(__cplusplus)
# pragma error_messages(off,E_EMPTY_DECLARATION)
#elif defined(HEDLEY_TI_VERSION)
# pragma diag_suppress 383
#endif
HEDLEY_DIAGNOSTIC_DISABLE_EXTRA_SEMI

HEDLEY_STATIC_ASSERT(sizeof(char) == 1, "char must be one byte");

Expand Down

0 comments on commit 9d193f2

Please sign in to comment.