Debian Codegraph @

src/mpt/check/compiler.hpp

raw
1 /* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */
2
3 #ifndef MPT_CHECK_COMPILER_HPP
4 #define MPT_CHECK_COMPILER_HPP
5
6 #include "mpt/base/detect_compiler.hpp"
7 #include "mpt/base/detect_quirks.hpp"
8 #include "mpt/base/compiletime_warning.hpp"
9
10 #ifndef MPT_CHECK_CXX_IGNORE_PREPROCESSOR
11 #if defined(MPT_COMPILER_QUIRK_MSVC_OLD_PREPROCESSOR)
12 MPT_WARNING("C++ preprocessor is not standard conformings.")
13 #endif
14 #endif
15
16 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_FASTMATH
17 #if MPT_COMPILER_MSVC
18 #if (defined(_M_FP_FAST) && (_M_FP_FAST == 1))
19 MPT_WARNING("C++ compiler has fast-math support enabled. This is not standard-conforming.")
20 #endif
21 #elif MPT_COMPILER_GCC || MPT_COMPILER_CLANG
22 #if (defined(__FAST_MATH__) && (__FAST_MATH__ == 1))
23 MPT_WARNING("C++ compiler has fast-math support enabled. This is not standard-conforming.")
24 #endif
25 #endif
26 #endif
27
28 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_FINITEMATH
29 #if MPT_COMPILER_MSVC
30 #if (defined(_M_FP_FAST) && (_M_FP_FAST == 1))
31 MPT_WARNING("C++ compiler assumes finite math only. This is not standard-conforming.")
32 #endif
33 #elif MPT_COMPILER_GCC || MPT_COMPILER_CLANG
34 #if (defined(__FINITE_MATH_ONLY__) && (__FINITE_MATH_ONLY__ == 1))
35 MPT_WARNING("C++ compiler assumes finite math only. This is not standard-conforming.")
36 #endif
37 #endif
38 #endif
39
40 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_NO_EXCEPTIONS
41 #if MPT_COMPILER_MSVC
42 #if !defined(_CPPUNWIND)
43 MPT_WARNING("C++ compiler has no exception support.")
44 #endif
45 #elif MPT_COMPILER_GCC
46 #if (!defined(__EXCEPTIONS) || (__EXCEPTIONS != 1))
47 MPT_WARNING("C++ compiler has no exception support.")
48 #endif
49 #elif MPT_COMPILER_CLANG
50 #if (!__has_feature(cxx_exceptions) && (!defined(__EXCEPTIONS) || (__EXCEPTIONS != 1)) && !defined(_CPPUNWIND))
51 MPT_WARNING("C++ compiler has no exception support.")
52 #else
53 #if (MPT_CXX_AT_LEAST(20) && !defined(__cpp_exceptions))
54 MPT_WARNING("C++ compiler has no exception support.")
55 #endif
56 #endif
57 #endif
58 #endif
59
60 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_NO_RTTI
61 #if MPT_COMPILER_MSVC
62 #if (!defined(_CPPRTTI) || (_CPPRTTI != 1))
63 MPT_WARNING("C++ compiler has no RTTI support.")
64 #endif
65 #elif MPT_COMPILER_GCC
66 #if (!defined(__GXX_RTTI) || (__GXX_RTTI != 1))
67 MPT_WARNING("C++ compiler has no RTTI support.")
68 #endif
69 #elif MPT_COMPILER_CLANG && !defined(_MSC_VER)
70 #if (!defined(__GXX_RTTI) || (__GXX_RTTI != 1))
71 MPT_WARNING("C++ compiler has no RTTI support.")
72 #endif
73 #endif
74 #endif
75
76 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_NO_UNICODE
77 #if !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
78 #if (!defined(__STDC_ISO_10646__) || (__STDC_ISO_10646__ <= 198700L))
79 #if !MPT_COMPILER_MSVC && !MPT_COMPILER_GCC && !MPT_COMPILER_CLANG
80 // Disabled for all known compilers, as none of them defines __STDC_ISO_10646__, even though all of them provide Unicode wchar_t.
81 MPT_WARNING("C++ compiler uses non-Unicode wchar_t.")
82 #endif
83 #endif
84 #endif
85 #endif
86
87 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_EBCDIC
88 #if defined(__STDC_MB_MIGHT_NEQ_WC__) && (__STDC_MB_MIGHT_NEQ_WC__ == 1)
89 #if !(MPT_COMPILER_CLANG && MPT_OS_FREEBSD)
90 // Disabled on FreeBSD because <https://github.com/llvm/llvm-project/blob/c7a56af3072c2fa89f0968d7f00b22f7bff0812b/clang/lib/Basic/Targets/OSTargets.h#L225>.
91 MPT_WARNING("C++ compiler uses a weird 8bit charset, maybe EBCDIC.")
92 #endif
93 #endif
94 #endif
95
96 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_NO_STDCPP_THREADS
97 #if MPT_PLATFORM_MULTITHREADED
98 #if !defined(MPT_COMPILER_QUIRK_NO_STDCPP_THREADS)
99 #if !defined(__STDCPP_THREADS__)
100 MPT_WARNING("C++ __STDCPP_THREADS__ is not defined. Non-conforming compiler detected.")
101 #else
102 #if (__STDCPP_THREADS__ != 1)
103 MPT_WARNING("C++ compiler has no thread support.")
104 #endif
105 #endif
106 #endif
107 #endif
108 #endif
109
110 #ifndef MPT_CHECK_CXX_IGNORE_WARNING_SINGLETHREADED_THREADSAFE_STATICS
111 #if !MPT_PLATFORM_MULTITHREADED
112 #if MPT_CXX_AT_LEAST(20) && MPT_COMPILER_GCC
113 #if (defined(__cpp_threadsafe_static_init) && (__cpp_threadsafe_static_init >= 200806L))
114 MPT_WARNING("C++ compiler provides threadsafe initialization of static variables, however the platform is single-threaded.")
115 #endif
116 #endif
117 #endif
118 #endif
119
120 #endif // MPT_CHECK_COMPILER_HPP