libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
explicit_declare.h
Go to the documentation of this file.
1// Copyright 2025 owent
2
3#pragma once
4
5// Import the C++20 feature-test macros
6#ifdef __has_include
7# if __has_include(<version>)
8# include <version>
9# endif
10#elif defined(_MSC_VER) && \
11 ((defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L))
12# if _MSC_VER >= 1922
13# include <version>
14# endif
15#endif
16
28#if defined(__cplusplus) && __cplusplus >= 201402L
29# define LIBCOPP_EXPLICIT_DEPRECATED_ATTR [[deprecated]]
30#elif defined(__clang__)
31# define LIBCOPP_EXPLICIT_DEPRECATED_ATTR __attribute__((deprecated))
32#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
33# define LIBCOPP_EXPLICIT_DEPRECATED_ATTR __attribute__((deprecated))
34#elif defined(_MSC_VER) && _MSC_VER >= 1400 // vs 2005 or higher
35# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
36# define LIBCOPP_EXPLICIT_DEPRECATED_ATTR [[deprecated]]
37# else
38# define LIBCOPP_EXPLICIT_DEPRECATED_ATTR __declspec(deprecated)
39# endif
40#else
41# define LIBCOPP_EXPLICIT_DEPRECATED_ATTR
42#endif
43
44#if defined(__cplusplus) && __cplusplus >= 201402L
45# define LIBCOPP_EXPLICIT_DEPRECATED_MSG(msg) [[deprecated(msg)]]
46#elif defined(__clang__)
47# define LIBCOPP_EXPLICIT_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
48#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
49# define LIBCOPP_EXPLICIT_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
50#elif defined(_MSC_VER) && _MSC_VER >= 1400 // vs 2005 or higher
51# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
52# define LIBCOPP_EXPLICIT_DEPRECATED_MSG(msg) [[deprecated(msg)]]
53# else
54# define LIBCOPP_EXPLICIT_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
55# endif
56#else
57# define LIBCOPP_EXPLICIT_DEPRECATED_MSG(msg)
58#endif
59
67#if defined(__cplusplus) && __cplusplus >= 201703L
68# define LIBCOPP_EXPLICIT_NODISCARD_ATTR [[nodiscard]]
69#elif defined(__clang__)
70# define LIBCOPP_EXPLICIT_NODISCARD_ATTR __attribute__((warn_unused_result))
71#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
72# define LIBCOPP_EXPLICIT_NODISCARD_ATTR __attribute__((warn_unused_result))
73#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
74# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
75# define LIBCOPP_EXPLICIT_NODISCARD_ATTR [[nodiscard]]
76# else
77# define LIBCOPP_EXPLICIT_NODISCARD_ATTR _Check_return_
78# endif
79#else
80# define LIBCOPP_EXPLICIT_NODISCARD_ATTR
81#endif
82
90#if defined(__cplusplus) && __cplusplus >= 201703L
91# define LIBCOPP_EXPLICIT_UNUSED_ATTR [[maybe_unused]]
92#elif defined(__clang__)
93# define LIBCOPP_EXPLICIT_UNUSED_ATTR __attribute__((unused))
94#elif defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
95# define LIBCOPP_EXPLICIT_UNUSED_ATTR __attribute__((unused))
96#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
97# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
98# define LIBCOPP_EXPLICIT_UNUSED_ATTR [[maybe_unused]]
99# else
100# define LIBCOPP_EXPLICIT_UNUSED_ATTR
101# endif
102#else
103# define LIBCOPP_EXPLICIT_UNUSED_ATTR
104#endif
105
114#if defined(__cplusplus) && __cplusplus >= 201703L
115# define LIBCOPP_EXPLICIT_FALLTHROUGH [[fallthrough]];
116#elif defined(__clang__) && ((__clang_major__ * 100) + __clang_minor__) >= 309
117# if defined(__apple_build_version__)
118# define LIBCOPP_EXPLICIT_FALLTHROUGH
119# elif defined(__has_warning) && __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
120# define LIBCOPP_EXPLICIT_FALLTHROUGH [[clang::fallthrough]];
121# else
122# define LIBCOPP_EXPLICIT_FALLTHROUGH
123# endif
124#elif defined(__GNUC__) && (__GNUC__ >= 7)
125# define LIBCOPP_EXPLICIT_FALLTHROUGH [[gnu::fallthrough]];
126#elif defined(_MSC_VER) && _MSC_VER >= 1700 // vs 2012 or higher
127# if _MSC_VER >= 1910 && defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
128# define LIBCOPP_EXPLICIT_FALLTHROUGH [[fallthrough]];
129# else
130# define LIBCOPP_EXPLICIT_FALLTHROUGH
131# endif
132#else
133# define LIBCOPP_EXPLICIT_FALLTHROUGH
134#endif
135
142#if defined(__clang__)
143# define LIBCOPP_EXPLICIT_MAY_ALIAS __attribute__((__may_alias__))
144#elif defined(__GNUC__) && (__GNUC__ >= 4)
145# define LIBCOPP_EXPLICIT_MAY_ALIAS __attribute__((__may_alias__))
146#else
147# define LIBCOPP_EXPLICIT_MAY_ALIAS
148#endif
149
150#if !defined(LIBCOPP_EXPLICIT_NORETURN_ATTR) && defined(__has_cpp_attribute)
151# if __has_cpp_attribute(noreturn)
152# define LIBCOPP_EXPLICIT_NORETURN_ATTR [[noreturn]]
153# endif
154#endif
155#ifndef LIBCOPP_EXPLICIT_NORETURN_ATTR
156# define LIBCOPP_EXPLICIT_NORETURN_ATTR
157#endif
158
159#ifndef LIBCOPP_EXPLICIT_UNREACHABLE
160# if defined(__cpp_lib_unreachable)
161# if __cpp_lib_unreachable
162# define LIBCOPP_EXPLICIT_UNREACHABLE() std::unreachable()
163# endif
164# endif
165# if !defined(LIBCOPP_EXPLICIT_UNREACHABLE) && defined(unreachable)
166# define LIBCOPP_EXPLICIT_UNREACHABLE() unreachable()
167# endif
168# if !defined(LIBCOPP_EXPLICIT_UNREACHABLE)
169# ifdef __GNUC__
170# ifdef __clang__
171# if __has_builtin(__builtin_unreachable)
172# define LIBCOPP_EXPLICIT_UNREACHABLE() __builtin_unreachable()
173# endif
174# else
175# if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
176# define LIBCOPP_EXPLICIT_UNREACHABLE() __builtin_unreachable()
177# endif
178# endif
179# endif
180# endif
181#endif
182#if !defined(LIBCOPP_EXPLICIT_UNREACHABLE)
183# if defined(_DEBUG) || !defined(NDEBUG)
184# define LIBCOPP_EXPLICIT_UNREACHABLE() std::abort()
185# else
186# define LIBCOPP_EXPLICIT_UNREACHABLE()
187# endif
188#endif