The Battle for Wesnoth  1.19.2+dev
global.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #ifdef _MSC_VER
19 #endif //_MSC_VER
20 
21 #ifdef NDEBUG
22 /*
23  * Wesnoth uses asserts to avoid undefined behaviour. For example, to make sure
24  * pointers are not nullptr before dereferencing them, or collections are not empty
25  * before accessing their elements. Therefore Wesnoth should not be compiled
26  * with assertions disabled.
27  */
28 #error "Compilation with NDEBUG defined isn't supported, Wesnoth depends on asserts."
29 #endif
30 
31 #define UNUSED(x) ((void)(x)) /* to avoid warnings */
32 
33 // To allow using some optional C++20 features
34 #if __cplusplus >= 202002L
35 #define HAVE_CXX20
36 #endif
37 
38 #if defined(__clang__)
39 #endif
40 
41 #if defined(__GNUC__) && !defined(__clang__)
42 #endif
43 
44 /*
45  * GCC-13 and GCC-14 warn about functions that return a reference and whose arguments also include a
46  * reference to a temporary, because they assume that the returned reference may point into the
47  * argument. This causes false positives for functions that take a std::map-like object as a
48  * separate argument (or as their "this" pointer), where the temporary being passed in is only used
49  * as a key to find an object in the map, and the returned reference points to an object owned by
50  * the map. Similarly, it's a false positive for data owned by a singleton.
51  *
52  * GCC-14 supports supressing the warnings with [[gnu::no_dangling]]. Clang complains about unknown
53  * attributes in the gnu:: namespace, so has to have the #if, and the #if means we need the #ifdef.
54  */
55 #ifdef __has_cpp_attribute
56 #if __has_cpp_attribute(gnu::no_dangling)
57 #define NOT_DANGLING [[gnu::no_dangling]]
58 #endif
59 #endif
60 #ifndef NOT_DANGLING
61 #define NOT_DANGLING
62 #endif