Commit 292750d27a67e10baee5206350b5cc39b4f61148
1 parent
88495513
Replace pragmas with macros
Fixes ##339
Showing
1 changed file
with
15 additions
and
12 deletions
include/cxxopts.hpp
| ... | ... | @@ -82,6 +82,13 @@ THE SOFTWARE. |
| 82 | 82 | #define CXXOPTS_NULL_DEREF_IGNORE |
| 83 | 83 | #endif |
| 84 | 84 | |
| 85 | +#if defined(__GNUC__) | |
| 86 | +#define DO_PRAGMA(x) _Pragma(#x) | |
| 87 | +#define CXXOPTS_DIAGNOSTIC_PUSH DO_PRAGMA(GCC diagnostic push) | |
| 88 | +#define CXXOPTS_DIAGNOSTIC_POP DO_PRAGMA(GCC diagnostic pop) | |
| 89 | +#define CXXOPTS_IGNORE_WARNING(x) DO_PRAGMA(GCC diagnostic ignored #x) | |
| 90 | +#endif | |
| 91 | + | |
| 85 | 92 | namespace cxxopts { |
| 86 | 93 | static constexpr struct { |
| 87 | 94 | uint8_t major, minor, patch; |
| ... | ... | @@ -112,14 +119,11 @@ toLocalString(std::string s) |
| 112 | 119 | return icu::UnicodeString::fromUTF8(std::move(s)); |
| 113 | 120 | } |
| 114 | 121 | |
| 115 | -#if defined(__GNUC__) | |
| 116 | 122 | // GNU GCC with -Weffc++ will issue a warning regarding the upcoming class, we want to silence it: |
| 117 | 123 | // warning: base class 'class std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual destructor |
| 118 | -#pragma GCC diagnostic push | |
| 119 | -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" | |
| 120 | -#pragma GCC diagnostic ignored "-Weffc++" | |
| 124 | +CXXOPTS_DIAGNOSTIC_PUSH | |
| 125 | +CXXOPTS_IGNORE_WARNING("-Wnon-virtual-dtor") | |
| 121 | 126 | // This will be ignored under other compilers like LLVM clang. |
| 122 | -#endif | |
| 123 | 127 | class UnicodeStringIterator : public |
| 124 | 128 | std::iterator<std::forward_iterator_tag, int32_t> |
| 125 | 129 | { |
| ... | ... | @@ -324,7 +328,6 @@ const std::string RQUOTE("’"); |
| 324 | 328 | // warning: base class 'class std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual destructor |
| 325 | 329 | #pragma GCC diagnostic push |
| 326 | 330 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" |
| 327 | -#pragma GCC diagnostic ignored "-Weffc++" | |
| 328 | 331 | // This will be ignored under other compilers like LLVM clang. |
| 329 | 332 | #endif |
| 330 | 333 | class Value : public std::enable_shared_from_this<Value> |
| ... | ... | @@ -370,9 +373,9 @@ class Value : public std::enable_shared_from_this<Value> |
| 370 | 373 | virtual bool |
| 371 | 374 | is_boolean() const = 0; |
| 372 | 375 | }; |
| 373 | -#if defined(__GNUC__) | |
| 374 | -#pragma GCC diagnostic pop | |
| 375 | -#endif | |
| 376 | + | |
| 377 | +CXXOPTS_DIAGNOSTIC_POP | |
| 378 | + | |
| 376 | 379 | namespace exceptions { |
| 377 | 380 | |
| 378 | 381 | class exception : public std::exception |
| ... | ... | @@ -1402,8 +1405,8 @@ class OptionValue |
| 1402 | 1405 | } |
| 1403 | 1406 | |
| 1404 | 1407 | #if defined(CXXOPTS_NULL_DEREF_IGNORE) |
| 1405 | -#pragma GCC diagnostic push | |
| 1406 | -#pragma GCC diagnostic ignored "-Wnull-dereference" | |
| 1408 | +CXXOPTS_DIAGNOSTIC_PUSH | |
| 1409 | +CXXOPTS_IGNORE_WARNING("-Wnull-dereference") | |
| 1407 | 1410 | #endif |
| 1408 | 1411 | |
| 1409 | 1412 | CXXOPTS_NODISCARD |
| ... | ... | @@ -1414,7 +1417,7 @@ class OptionValue |
| 1414 | 1417 | } |
| 1415 | 1418 | |
| 1416 | 1419 | #if defined(CXXOPTS_NULL_DEREF_IGNORE) |
| 1417 | -#pragma GCC diagnostic pop | |
| 1420 | +CXXOPTS_DIAGNOSTIC_POP | |
| 1418 | 1421 | #endif |
| 1419 | 1422 | |
| 1420 | 1423 | // TODO: maybe default options should count towards the number of arguments | ... | ... |