Skip to content

Commit

Permalink
Don't emit diagnostic pragmas on GCC < 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
hirrolot committed Apr 6, 2021
1 parent 66fb639 commit e4c8e46
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Do **not** suppress `-Wmisleading-indentation` (GCC) automatically in `match99`.

### Fixed

- `#pragma GCC diagnostic` inside functions error on GCC older than 4.6 ([issue 8](https://github.com/Hirrolot/datatype99/issues/8)).

## [1.0.0] - 2021-03-28

### Added
Expand Down
35 changes: 25 additions & 10 deletions datatype99.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,33 +289,48 @@ static const UnitT99 unit_v99 = '\0';
#define DATATYPE99_PRIV_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
#define DATATYPE99_PRIV_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE _Pragma("clang diagnostic ignored \"-Wreturn-type\"")
#define DATATYPE99_PRIV_CONST

#elif defined(__GNUC__)

// Diagnostic pragmas are not allowed inside functions on ancient GCC versions.
// See <https://github.com/Hirrolot/datatype99/issues/8>.
#if (__GNUC__ == 4 && __GNUC__MINOR__ >= 6) || __GNUC__ > 4
#define DATATYPE99_PRIV_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define DATATYPE99_PRIV_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE _Pragma("GCC diagnostic ignored \"-Wreturn-type\"")
#define DATATYPE99_PRIV_CONST __attribute__((const))
#endif

#define DATATYPE99_PRIV_UNUSED __attribute__((unused))
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define DATATYPE99_PRIV_CONST __attribute__((const))

#else
#endif

#define DATATYPE99_PRIV_CTOR_ATTRS DATATYPE99_PRIV_WARN_UNUSED_RESULT DATATYPE99_PRIV_CONST

#ifndef DATATYPE99_PRIV_DIAGNOSTIC_PUSH
#define DATATYPE99_PRIV_DIAGNOSTIC_PUSH
#endif

#ifndef DATATYPE99_PRIV_DIAGNOSTIC_POP
#define DATATYPE99_PRIV_DIAGNOSTIC_POP
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE
#define DATATYPE99_PRIV_CONST
#endif

#ifndef DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE
#endif

#ifdef __GNUC__
#define DATATYPE99_PRIV_UNUSED __attribute__((unused))
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#ifndef DATATYPE99_PRIV_UNUSED
#define DATATYPE99_PRIV_UNUSED
#endif

#ifndef DATATYPE99_PRIV_WARN_UNUSED_RESULT
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT
#endif

#define DATATYPE99_PRIV_CTOR_ATTRS DATATYPE99_PRIV_WARN_UNUSED_RESULT DATATYPE99_PRIV_CONST
#ifndef DATATYPE99_PRIV_CONST
#define DATATYPE99_PRIV_CONST
#endif
// } (Compiler-specific stuff)

// Arity specifiers {
Expand Down

0 comments on commit e4c8e46

Please sign in to comment.