Mantid
Loading...
Searching...
No Matches
WarningSuppressions.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2013 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9/* A system-wide file to contain, e.g., useful system-dependent macros
10 for suppressing compiler warnings.
11*/
12
18#if defined(__clang__)
19#define CLANG_VERSION ((__clang_major__ * 100) + __clang_minor__)
20#endif
21
22#if defined(__GNUC__) && !(defined(__INTEL_COMPILER)) && !defined(__clang__)
23#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
24#endif
25
26#if defined(GCC_VERSION) || defined(CLANG_VERSION)
27// things to make the macros clearer
28#define GNU_DIAG_MAKE_WARNING(x) "-W" x
29#define GNU_DIAG_DO_PRAGMA(x) _Pragma(#x)
30
31#if defined(GCC_VERSION)
32#define GNU_DIAG_PRAGMA(x) GNU_DIAG_DO_PRAGMA(GCC diagnostic x)
33#else
34#define GNU_DIAG_PRAGMA(x) GNU_DIAG_DO_PRAGMA(clang diagnostic x)
35#endif
36
37// the following were previously defined in Poco/Platform_POSIX.h
38#ifdef GNU_DIAG_ON
39#undef GNU_DIAG_ON
40#endif
41#ifdef GNU_DIAG_OFF
42#undef GNU_DIAG_OFF
43#endif
44
45#if defined(GCC_VERSION)
46// define macros for turning the warning suppression on/off for GCC
47// note that we turn off unknown warnings here as well so that we can use the
48// same macro for GCC and clang.
49// clang-format off
50#define GNU_DIAG_OFF(x) \
51 GNU_DIAG_PRAGMA(push) \
52 GNU_DIAG_PRAGMA(ignored GNU_DIAG_MAKE_WARNING("pragmas")) \
53 GNU_DIAG_PRAGMA(ignored GNU_DIAG_MAKE_WARNING(x))
54#define GNU_DIAG_ON(x) GNU_DIAG_PRAGMA(pop)
55
56// clang-format on
57
58#elif defined(CLANG_VERSION) && CLANG_VERSION >= 306
59// define macros for turning the warning suppression on/off for clang
60// note that we turn off unknown warnings here as well so that we can use the
61// same macro for GCC and clang.
62// clang-format off
63#define GNU_DIAG_OFF(x) \
64 GNU_DIAG_PRAGMA(push) \
65 GNU_DIAG_PRAGMA(ignored GNU_DIAG_MAKE_WARNING("unknown-pragmas")) \
66 GNU_DIAG_PRAGMA(ignored GNU_DIAG_MAKE_WARNING("unknown-warning-option")) \
67 GNU_DIAG_PRAGMA(ignored GNU_DIAG_MAKE_WARNING(x))
68#define GNU_DIAG_ON(x) GNU_DIAG_PRAGMA(pop)
69// clang-format on
70#endif
71#else
72// neither clang or GCC
73#define GNU_DIAG_OFF(x)
74#define GNU_DIAG_ON(x)
75#endif
76
77// Similar macros for MSVC
78#if defined(_MSC_VER)
79// clang-format off
80#define MSVC_DIAG_OFF(id) \
81 __pragma(warning(push)) \
82 __pragma(warning(disable : id))
83#define MSVC_DIAG_ON(id) __pragma(warning(pop))
84// clang-format on
85#else
86#define MSVC_DIAG_OFF(x)
87#define MSVC_DIAG_ON(x)
88#endif
89
90// Defining this macro separately since clang-tidy tries to add spaces around
91// the hyphen and we use it in a lot of test files.
92// clang-format off
93#if defined(__cplusplus) && defined(GCC_VERSION) && GCC_VERSION >= 50000
94#define GNU_DIAG_OFF_SUGGEST_OVERRIDE GNU_DIAG_OFF("suggest-override")
95#define GNU_DIAG_ON_SUGGEST_OVERRIDE GNU_DIAG_ON("suggest-override")
96#elif defined(__cplusplus) && defined(CLANG_VERSION) && CLANG_VERSION >= 306
97#define GNU_DIAG_OFF_SUGGEST_OVERRIDE GNU_DIAG_OFF("inconsistent-missing-override")
98#define GNU_DIAG_ON_SUGGEST_OVERRIDE GNU_DIAG_ON("inconsistent-missing-override")
99#else
100#define GNU_DIAG_OFF_SUGGEST_OVERRIDE
101#define GNU_DIAG_ON_SUGGEST_OVERRIDE
102#endif
103// clang-format on
104
105#if defined(GCC_VERSION) || defined(CLANG_VERSION)
106#define GNU_UNUSED_FUNCTION __attribute__((unused))
107#else
108#define GNU_UNUSED_FUNCTION
109#endif