The Battle for Wesnoth  1.15.2+dev
global.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #ifdef _MSC_VER
18 
19 // Enable C99 support
20 #define STDC99
21 
22 #endif //_MSC_VER
23 
24 #ifdef NDEBUG
25 /*
26  * Wesnoth uses asserts to avoid undefined behaviour. For example, to make sure
27  * pointers are not nullptr before dereferencing them, or collections are not empty
28  * before accessing their elements. Therefore Wesnoth should not be compiled
29  * with assertions disabled.
30  */
31 #error "Compilation with NDEBUG defined isn't supported, Wesnoth depends on asserts."
32 #endif
33 
34 #define UNUSED(x) ((void)(x)) /* to avoid warnings */
35 
36 // To allow using some optional C++17 features
37 #if __cplusplus >= 201703L
38 #define HAVE_CXX17
39 #endif
40 
41 // Some C++11 features are not available on all supported platforms
42 #if defined(_MSC_VER)
43 // MSVC supports these starting in MSVC 2015
44 #if _MSC_VER >= 1900
45 #else
46 #endif
47 // MSVC supports these starting in 2017?
48 // Some sources claim MSVC 2015 supports them, but let's be safe...
49 #if _MSC_VER >= 1910
50 #define DEPRECATED(reason) [[deprecated(reason)]]
51 #if _MSVC_LANG > 201402 // fallthrough only supported when MSVC targets later than C++14
52 #define FALLTHROUGH [[fallthrough]]
53 #else
54 #define FALLTHROUGH
55 #endif
56 #else
57 #define DEPRECATED(reason) __declspec(deprecated)
58 #define FALLTHROUGH
59 #endif
60 #endif
61 
62 #if defined(__clang__)
63 #include <ciso646> // To ensure standard library version macros are defined
64 
65 // All supported versions of clang have these
66 #define FALLTHROUGH [[clang::fallthrough]]
67 // Use GCC-style attribute because the __has_cpp_attribute feature-checking macro doesn't exist in clang 3.5
68 #define DEPRECATED(reason) __attribute__((deprecated(reason)))
69 
70 #endif
71 
72 #if defined(__GNUC__) && !defined(__clang__)
73 // GCC supports these from 4.8 up
74 
75 // Deprecated is supported from 4.9 up
76 #if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9)
77 #define DEPRECATED(reason) [[deprecated(reason)]]
78 #else
79 #define DEPRECATED(reason) __attribute__((deprecated(reason)))
80 #endif
81 
82 // Fallthrough is supported from GCC 7 up
83 #if __GNUC__ >= 7
84 #define FALLTHROUGH [[fallthrough]]
85 #else
86 #define FALLTHROUGH
87 #endif
88 #endif