Skip to content

Commit 344206e

Browse files
committed
Don't emit diagnostic pragmas on GCC < 4.6
1 parent 746449e commit 344206e

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

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

18+
### Fixed
19+
20+
- `#pragma GCC diagnostic` inside functions error on GCC older than 4.6 ([issue 8](https://github.com/Hirrolot/datatype99/issues/8)).
21+
1822
## [1.0.0] - 2021-03-28
1923

2024
### Added

datatype99.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -289,33 +289,48 @@ static const UnitT99 unit_v99 = '\0';
289289
#define DATATYPE99_PRIV_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
290290
#define DATATYPE99_PRIV_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
291291
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE _Pragma("clang diagnostic ignored \"-Wreturn-type\"")
292-
#define DATATYPE99_PRIV_CONST
293292

294293
#elif defined(__GNUC__)
295294

295+
// Diagnostic pragmas are not allowed inside functions on ancient GCC versions.
296+
// See <https://github.com/Hirrolot/datatype99/issues/8>.
297+
#if (__GNUC__ == 4 && __GNUC__MINOR__ >= 6) || __GNUC__ > 4
296298
#define DATATYPE99_PRIV_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
297299
#define DATATYPE99_PRIV_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
298300
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE _Pragma("GCC diagnostic ignored \"-Wreturn-type\"")
299-
#define DATATYPE99_PRIV_CONST __attribute__((const))
301+
#endif
302+
303+
#define DATATYPE99_PRIV_UNUSED __attribute__((unused))
304+
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
305+
#define DATATYPE99_PRIV_CONST __attribute__((const))
300306

301-
#else
307+
#endif
302308

309+
#define DATATYPE99_PRIV_CTOR_ATTRS DATATYPE99_PRIV_WARN_UNUSED_RESULT DATATYPE99_PRIV_CONST
310+
311+
#ifndef DATATYPE99_PRIV_DIAGNOSTIC_PUSH
303312
#define DATATYPE99_PRIV_DIAGNOSTIC_PUSH
313+
#endif
314+
315+
#ifndef DATATYPE99_PRIV_DIAGNOSTIC_POP
304316
#define DATATYPE99_PRIV_DIAGNOSTIC_POP
305-
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE
306-
#define DATATYPE99_PRIV_CONST
317+
#endif
307318

319+
#ifndef DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE
320+
#define DATATYPE99_PRIV_SUPPRESS_W_RETURN_TYPE
308321
#endif
309322

310-
#ifdef __GNUC__
311-
#define DATATYPE99_PRIV_UNUSED __attribute__((unused))
312-
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
313-
#else
323+
#ifndef DATATYPE99_PRIV_UNUSED
314324
#define DATATYPE99_PRIV_UNUSED
325+
#endif
326+
327+
#ifndef DATATYPE99_PRIV_WARN_UNUSED_RESULT
315328
#define DATATYPE99_PRIV_WARN_UNUSED_RESULT
316329
#endif
317330

318-
#define DATATYPE99_PRIV_CTOR_ATTRS DATATYPE99_PRIV_WARN_UNUSED_RESULT DATATYPE99_PRIV_CONST
331+
#ifndef DATATYPE99_PRIV_CONST
332+
#define DATATYPE99_PRIV_CONST
333+
#endif
319334
// } (Compiler-specific stuff)
320335

321336
// Arity specifiers {

0 commit comments

Comments
 (0)