diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-30 07:07:48 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-07-30 07:07:48 +0000 |
commit | d83536c980fb96a880def3e952eb4920815eeb51 (patch) | |
tree | ac970bbba01d5b04b4d0ab7c0175e996d7468875 /internal.h | |
parent | 7018acc946882f21d519af7c42ccf84b22a46b27 (diff) | |
download | ruby-d83536c980fb96a880def3e952eb4920815eeb51.tar.gz |
reduce copy & paste
We see several occurrence of "diagnostic push/pop" so why not
make them macros. Tested on GCC8 / Clang 6.
Note that ruby.h is intentionally left untouched because we don't
want to introduce new public macros.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r-- | internal.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/internal.h b/internal.h index 0d5c952158..628f0d4e20 100644 --- a/internal.h +++ b/internal.h @@ -2147,6 +2147,43 @@ rb_obj_builtin_type(VALUE obj) # define BITFIELD(type) unsigned int #endif +#if defined(_MSC_VER) +# define COMPILER_WARNING_PUSH __pragma(warning(push)) +# define COMPILER_WARNING_POP __pragma(warning(pop)) +# define COMPILER_WARNING_ERROR(flag) __pragma(warning(error: flag))) +# define COMPILER_WARNING_IGNORED(flag) __pragma(warning(suppress: flag))) + +#elif defined(__clang__) /* clang 2.6 already had this feature */ +# define COMPILER_WARNING_PUSH _Pragma("clang diagnostic push") +# define COMPILER_WARNING_POP _Pragma("clang diagnostic pop") +# define COMPILER_WARNING_SPECIFIER(kind, msg) \ + clang diagnostic kind # msg +# define COMPILER_WARNING_ERROR(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(error, flag)) +# define COMPILER_WARNING_IGNORED(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(ignored, flag)) + +#elif GCC_VERSION_SINCE(4, 2, 0) +/* https://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Diagnostic-Pragmas.html */ +# define COMPILER_WARNING_PUSH _Pragma("GCC diagnostic push") +# define COMPILER_WARNING_POP _Pragma("GCC diagnostic pop") +# define COMPILER_WARNING_SPECIFIER(kind, msg) \ + GCC diagnostic kind # msg +# define COMPILER_WARNING_ERROR(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(error, flag)) +# define COMPILER_WARNING_IGNORED(flag) \ + COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(ignored, flag)) + +#else /* other compilers to follow? */ +# define COMPILER_WARNING_PUSH /* nop */ +# define COMPILER_WARNING_POP /* nop */ +# define COMPILER_WARNING_ERROR(cond, flag) /* nop */ +# define COMPILER_WARNING_ignored(cond, flag) /* nop */ +#endif + +#define COMPILER_WARNING_PRAGMA(str) COMPILER_WARNING_PRAGMA_(str) +#define COMPILER_WARNING_PRAGMA_(str) _Pragma(#str) + #if defined(__cplusplus) #if 0 { /* satisfy cc-mode */ |