Commit 292750d27a67e10baee5206350b5cc39b4f61148

Authored by Jarryd Beck
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,6 +82,13 @@ THE SOFTWARE.
82 #define CXXOPTS_NULL_DEREF_IGNORE 82 #define CXXOPTS_NULL_DEREF_IGNORE
83 #endif 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 namespace cxxopts { 92 namespace cxxopts {
86 static constexpr struct { 93 static constexpr struct {
87 uint8_t major, minor, patch; 94 uint8_t major, minor, patch;
@@ -112,14 +119,11 @@ toLocalString(std::string s) @@ -112,14 +119,11 @@ toLocalString(std::string s)
112 return icu::UnicodeString::fromUTF8(std::move(s)); 119 return icu::UnicodeString::fromUTF8(std::move(s));
113 } 120 }
114 121
115 -#if defined(__GNUC__)  
116 // GNU GCC with -Weffc++ will issue a warning regarding the upcoming class, we want to silence it: 122 // GNU GCC with -Weffc++ will issue a warning regarding the upcoming class, we want to silence it:
117 // warning: base class 'class std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual destructor 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 // This will be ignored under other compilers like LLVM clang. 126 // This will be ignored under other compilers like LLVM clang.
122 -#endif  
123 class UnicodeStringIterator : public 127 class UnicodeStringIterator : public
124 std::iterator<std::forward_iterator_tag, int32_t> 128 std::iterator<std::forward_iterator_tag, int32_t>
125 { 129 {
@@ -324,7 +328,6 @@ const std::string RQUOTE(&quot;’&quot;); @@ -324,7 +328,6 @@ const std::string RQUOTE(&quot;’&quot;);
324 // warning: base class 'class std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual destructor 328 // warning: base class 'class std::enable_shared_from_this<cxxopts::Value>' has accessible non-virtual destructor
325 #pragma GCC diagnostic push 329 #pragma GCC diagnostic push
326 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor" 330 #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
327 -#pragma GCC diagnostic ignored "-Weffc++"  
328 // This will be ignored under other compilers like LLVM clang. 331 // This will be ignored under other compilers like LLVM clang.
329 #endif 332 #endif
330 class Value : public std::enable_shared_from_this<Value> 333 class Value : public std::enable_shared_from_this<Value>
@@ -370,9 +373,9 @@ class Value : public std::enable_shared_from_this&lt;Value&gt; @@ -370,9 +373,9 @@ class Value : public std::enable_shared_from_this&lt;Value&gt;
370 virtual bool 373 virtual bool
371 is_boolean() const = 0; 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 namespace exceptions { 379 namespace exceptions {
377 380
378 class exception : public std::exception 381 class exception : public std::exception
@@ -1402,8 +1405,8 @@ class OptionValue @@ -1402,8 +1405,8 @@ class OptionValue
1402 } 1405 }
1403 1406
1404 #if defined(CXXOPTS_NULL_DEREF_IGNORE) 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 #endif 1410 #endif
1408 1411
1409 CXXOPTS_NODISCARD 1412 CXXOPTS_NODISCARD
@@ -1414,7 +1417,7 @@ class OptionValue @@ -1414,7 +1417,7 @@ class OptionValue
1414 } 1417 }
1415 1418
1416 #if defined(CXXOPTS_NULL_DEREF_IGNORE) 1419 #if defined(CXXOPTS_NULL_DEREF_IGNORE)
1417 -#pragma GCC diagnostic pop 1420 +CXXOPTS_DIAGNOSTIC_POP
1418 #endif 1421 #endif
1419 1422
1420 // TODO: maybe default options should count towards the number of arguments 1423 // TODO: maybe default options should count towards the number of arguments