diagnostic.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2016 Jakub Szuppe <j.szuppe@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_DETAIL_DIAGNOSTIC_HPP
  11. #define BOOST_COMPUTE_DETAIL_DIAGNOSTIC_HPP
  12. // Macros for suppressing warnings for GCC version 4.6 or later. Usage:
  13. //
  14. // BOOST_COMPUTE_BOOST_COMPUTE_GCC_DIAG_OFF(sign-compare);
  15. // if(a < b){
  16. // BOOST_COMPUTE_BOOST_COMPUTE_GCC_DIAG_ON(sign-compare);
  17. //
  18. // Source: https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines
  19. #if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 402
  20. #define BOOST_COMPUTE_GCC_DIAG_STR(s) #s
  21. #define BOOST_COMPUTE_GCC_DIAG_JOINSTR(x,y) BOOST_COMPUTE_GCC_DIAG_STR(x ## y)
  22. # define BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(x) _Pragma (#x)
  23. # define BOOST_COMPUTE_GCC_DIAG_PRAGMA(x) BOOST_COMPUTE_GCC_DIAG_DO_PRAGMA(GCC diagnostic x)
  24. # if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406
  25. # define BOOST_COMPUTE_GCC_DIAG_OFF(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(push) \
  26. BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
  27. # define BOOST_COMPUTE_GCC_DIAG_ON(x) BOOST_COMPUTE_GCC_DIAG_PRAGMA(pop)
  28. # else
  29. # define BOOST_COMPUTE_GCC_DIAG_OFF(x) \
  30. BOOST_COMPUTE_GCC_DIAG_PRAGMA(ignored BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
  31. # define BOOST_COMPUTE_GCC_DIAG_ON(x) \
  32. BOOST_COMPUTE_GCC_DIAG_PRAGMA(warning BOOST_COMPUTE_GCC_DIAG_JOINSTR(-W,x))
  33. # endif
  34. #else // Ensure these macros do nothing for other compilers.
  35. # define BOOST_COMPUTE_GCC_DIAG_OFF(x)
  36. # define BOOST_COMPUTE_GCC_DIAG_ON(x)
  37. #endif
  38. // Macros for suppressing warnings for Clang.
  39. //
  40. // BOOST_COMPUTE_BOOST_COMPUTE_CLANG_DIAG_OFF(sign-compare);
  41. // if(a < b){
  42. // BOOST_COMPUTE_BOOST_COMPUTE_CLANG_DIAG_ON(sign-compare);
  43. //
  44. // Source: https://svn.boost.org/trac/boost/wiki/Guidelines/WarningsGuidelines
  45. #ifdef __clang__
  46. # define BOOST_COMPUTE_CLANG_DIAG_STR(s) # s
  47. // stringize s to "no-sign-compare"
  48. # define BOOST_COMPUTE_CLANG_DIAG_JOINSTR(x,y) BOOST_COMPUTE_CLANG_DIAG_STR(x ## y)
  49. // join -W with no-unused-variable to "-Wno-sign-compare"
  50. # define BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(x) _Pragma (#x)
  51. // _Pragma is unary operator #pragma ("")
  52. # define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x) \
  53. BOOST_COMPUTE_CLANG_DIAG_DO_PRAGMA(clang diagnostic x)
  54. # define BOOST_COMPUTE_CLANG_DIAG_OFF(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(push) \
  55. BOOST_COMPUTE_CLANG_DIAG_PRAGMA(ignored BOOST_COMPUTE_CLANG_DIAG_JOINSTR(-W,x))
  56. // For example: #pragma clang diagnostic ignored "-Wno-sign-compare"
  57. # define BOOST_COMPUTE_CLANG_DIAG_ON(x) BOOST_COMPUTE_CLANG_DIAG_PRAGMA(pop)
  58. // For example: #pragma clang diagnostic warning "-Wno-sign-compare"
  59. #else // Ensure these macros do nothing for other compilers.
  60. # define BOOST_COMPUTE_CLANG_DIAG_OFF(x)
  61. # define BOOST_COMPUTE_CLANG_DIAG_ON(x)
  62. # define BOOST_COMPUTE_CLANG_DIAG_PRAGMA(x)
  63. #endif
  64. // Macros for suppressing warnings for MSVC. Usage:
  65. //
  66. // BOOST_COMPUTE_BOOST_COMPUTE_MSVC_DIAG_OFF(4018); //sign-compare
  67. // if(a < b){
  68. // BOOST_COMPUTE_BOOST_COMPUTE_MSVC_DIAG_ON(4018);
  69. //
  70. #if defined(_MSC_VER)
  71. # define BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(x) __pragma(x)
  72. # define BOOST_COMPUTE_MSVC_DIAG_PRAGMA(x) \
  73. BOOST_COMPUTE_MSVC_DIAG_DO_PRAGMA(warning(x))
  74. # define BOOST_COMPUTE_MSVC_DIAG_OFF(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(push) \
  75. BOOST_COMPUTE_MSVC_DIAG_PRAGMA(disable: x)
  76. # define BOOST_COMPUTE_MSVC_DIAG_ON(x) BOOST_COMPUTE_MSVC_DIAG_PRAGMA(pop)
  77. #else // Ensure these macros do nothing for other compilers.
  78. # define BOOST_COMPUTE_MSVC_DIAG_OFF(x)
  79. # define BOOST_COMPUTE_MSVC_DIAG_ON(x)
  80. #endif
  81. // Macros for suppressing warnings for GCC, Clang and MSVC. Usage:
  82. //
  83. // BOOST_COMPUTE_DIAG_OFF(sign-compare, sign-compare, 4018);
  84. // if(a < b){
  85. // BOOST_COMPUTE_DIAG_ON(sign-compare, sign-compare, 4018);
  86. //
  87. #if defined(_MSC_VER) // MSVC
  88. # define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc) BOOST_COMPUTE_MSVC_DIAG_OFF(msvc)
  89. # define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc) BOOST_COMPUTE_MSVC_DIAG_ON(msvc)
  90. #elif defined(__clang__) // Clang
  91. # define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc) BOOST_COMPUTE_CLANG_DIAG_OFF(clang)
  92. # define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc) BOOST_COMPUTE_CLANG_DIAG_ON(clang)
  93. #elif defined(__GNUC__) // GCC/G++
  94. # define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc) BOOST_COMPUTE_GCC_DIAG_OFF(gcc)
  95. # define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc) BOOST_COMPUTE_GCC_DIAG_ON(gcc)
  96. #else // Ensure these macros do nothing for other compilers.
  97. # define BOOST_COMPUTE_DIAG_OFF(gcc, clang, msvc)
  98. # define BOOST_COMPUTE_DIAG_ON(gcc, clang, msvc)
  99. #endif
  100. #define BOOST_COMPUTE_DISABLE_DEPRECATED_DECLARATIONS() \
  101. BOOST_COMPUTE_DIAG_OFF(deprecated-declarations, deprecated-declarations, 4996)
  102. #define BOOST_COMPUTE_ENABLE_DEPRECATED_DECLARATIONS() \
  103. BOOST_COMPUTE_DIAG_ON(deprecated-declarations, deprecated-declarations, 4996);
  104. #endif /* BOOST_COMPUTE_DETAIL_DIAGNOSTIC_HPP */