From e4c8e4688612cb63e471d7f7f1dcd358089ed467 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Tue, 6 Apr 2021 13:18:26 +0600 Subject: [PATCH] Don't emit diagnostic pragmas on GCC < 4.6 --- CHANGELOG.md | 4 ++++ datatype99.h | 35 +++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51ec69f..f0f6098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/datatype99.h b/datatype99.h index 0406555..5af5338 100644 --- a/datatype99.h +++ b/datatype99.h @@ -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 . +#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 {