aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/raw_pdb/src/Foundation/PDB_Macros.h
blob: fddcccfa495891f48ebed8f490b1c43b5ca09871 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2011-2022, Molecular Matters GmbH <[email protected]>
// See LICENSE.txt for licensing details (2-clause BSD License: https://opensource.org/licenses/BSD-2-Clause)

#pragma once

#include "PDB_Platform.h"
#include "PDB_TypeTraits.h"


// ------------------------------------------------------------------------------------------------
// ATTRIBUTES
// ------------------------------------------------------------------------------------------------

// Indicates to the compiler that the return value of a function or class should not be ignored.
#if PDB_CPP_17
#	define PDB_NO_DISCARD									[[nodiscard]]
#else
#	define PDB_NO_DISCARD
#endif

// Indicates to the compiler that a function does not throw an exception.
#define PDB_NO_EXCEPT										noexcept


// ------------------------------------------------------------------------------------------------
// SPECIAL MEMBER FUNCTIONS
// ------------------------------------------------------------------------------------------------

// Default special member functions.
#define PDB_DEFAULT_COPY_CONSTRUCTOR(_name)					_name(const _name&) PDB_NO_EXCEPT = default
#define PDB_DEFAULT_COPY_ASSIGNMENT(_name)					_name& operator=(const _name&) PDB_NO_EXCEPT = default
#define PDB_DEFAULT_MOVE_CONSTRUCTOR(_name)					_name(_name&&) PDB_NO_EXCEPT = default
#define PDB_DEFAULT_MOVE_ASSIGNMENT(_name)					_name& operator=(_name&&) PDB_NO_EXCEPT = default

// Default copy member functions.
#define PDB_DEFAULT_COPY(_name)								PDB_DEFAULT_COPY_CONSTRUCTOR(_name); PDB_DEFAULT_COPY_ASSIGNMENT(_name)

// Default move member functions.
#define PDB_DEFAULT_MOVE(_name)								PDB_DEFAULT_MOVE_CONSTRUCTOR(_name); PDB_DEFAULT_MOVE_ASSIGNMENT(_name)

// Single macro to default all copy and move member functions.
#define PDB_DEFAULT_COPY_MOVE(_name)						PDB_DEFAULT_COPY(_name); PDB_DEFAULT_MOVE(_name)

// Disable special member functions.
#define PDB_DISABLE_COPY_CONSTRUCTOR(_name)					_name(const _name&) PDB_NO_EXCEPT = delete
#define PDB_DISABLE_COPY_ASSIGNMENT(_name)					_name& operator=(const _name&) PDB_NO_EXCEPT = delete
#define PDB_DISABLE_MOVE_CONSTRUCTOR(_name)					_name(_name&&) PDB_NO_EXCEPT = delete
#define PDB_DISABLE_MOVE_ASSIGNMENT(_name)					_name& operator=(_name&&) PDB_NO_EXCEPT = delete

// Disable copy member functions.
#define PDB_DISABLE_COPY(_name)								PDB_DISABLE_COPY_CONSTRUCTOR(_name); PDB_DISABLE_COPY_ASSIGNMENT(_name)

// Disable move member functions.
#define PDB_DISABLE_MOVE(_name)								PDB_DISABLE_MOVE_CONSTRUCTOR(_name); PDB_DISABLE_MOVE_ASSIGNMENT(_name)

// Single macro to disable all copy and move member functions.
#define PDB_DISABLE_COPY_MOVE(_name)						PDB_DISABLE_COPY(_name); PDB_DISABLE_MOVE(_name)


// ------------------------------------------------------------------------------------------------
// COMPILER WARNINGS
// ------------------------------------------------------------------------------------------------

#if PDB_COMPILER_MSVC
#	define PDB_PRAGMA(_x)									__pragma(_x)

#	define PDB_PUSH_WARNING_MSVC							PDB_PRAGMA(warning(push))
#	define PDB_SUPPRESS_WARNING_MSVC(_number)				PDB_PRAGMA(warning(suppress : _number))
#	define PDB_DISABLE_WARNING_MSVC(_number)				PDB_PRAGMA(warning(disable : _number))
#	define PDB_POP_WARNING_MSVC								PDB_PRAGMA(warning(pop))

#	define PDB_PUSH_WARNING_CLANG
#	define PDB_DISABLE_WARNING_CLANG(_diagnostic)
#	define PDB_POP_WARNING_CLANG
#elif PDB_COMPILER_CLANG
#	define PDB_PRAGMA(_x)									_Pragma(#_x)

#	define PDB_PUSH_WARNING_MSVC
#	define PDB_SUPPRESS_WARNING_MSVC(_number)
#	define PDB_DISABLE_WARNING_MSVC(_number)
#	define PDB_POP_WARNING_MSVC

#	define PDB_PUSH_WARNING_CLANG							PDB_PRAGMA(clang diagnostic push)
#	define PDB_DISABLE_WARNING_CLANG(_diagnostic)			PDB_PRAGMA(clang diagnostic ignored _diagnostic)
#	define PDB_POP_WARNING_CLANG							PDB_PRAGMA(clang diagnostic pop)
#elif PDB_COMPILER_GCC
#	define PDB_PRAGMA(_x)									_Pragma(#_x)

#	define PDB_PUSH_WARNING_MSVC
#	define PDB_SUPPRESS_WARNING_MSVC(_number)
#	define PDB_DISABLE_WARNING_MSVC(_number)
#	define PDB_POP_WARNING_MSVC

#	define PDB_PUSH_WARNING_CLANG
#	define PDB_DISABLE_WARNING_CLANG(_diagnostic)
#	define PDB_POP_WARNING_CLANG
#endif


// ------------------------------------------------------------------------------------------------
// MISCELLANEOUS
// ------------------------------------------------------------------------------------------------

// Trick to make other macros require a semicolon at the end.
#define PDB_REQUIRE_SEMICOLON								static_assert(true, "")

// Defines a C-like flexible array member.
#define PDB_FLEXIBLE_ARRAY_MEMBER(_type, _name)				\
	PDB_PUSH_WARNING_MSVC									\
	PDB_PUSH_WARNING_CLANG									\
	PDB_DISABLE_WARNING_MSVC(4200)							\
	PDB_DISABLE_WARNING_CLANG("-Wzero-length-array")		\
	_type _name[0];											\
	PDB_POP_WARNING_MSVC									\
	PDB_POP_WARNING_CLANG									\
	PDB_REQUIRE_SEMICOLON

// Casts any value to the value of the underlying type.
#define PDB_AS_UNDERLYING(_value)							static_cast<typename PDB::underlying_type<decltype(_value)>::type>(_value)

// Signals to the compiler that a function should be ignored, but have its argument list parsed (and "used", so as to not generate "unused variable" warnings).
#if PDB_COMPILER_MSVC
#	define PDB_NOOP											__noop
#else
#	define PDB_NOOP(...)									(void)sizeof(__VA_ARGS__)
#endif