azure-core
Loading...
Searching...
No Matches
azure_assert.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
16#pragma once
17
19
20#include <cstdlib>
21#include <string>
22
23#if defined(NDEBUG)
24
25/*
26 * NDEBUG = defined = Build is on Release
27 * Define AZURE_ASSERT to call abort directly on exp == false
28 */
29
30#define AZURE_ASSERT(exp) \
31 do \
32 { \
33 if (!(exp)) \
34 { \
35 std::abort(); \
36 } \
37 } while (0)
38
39#define AZURE_ASSERT_MSG(exp, msg) AZURE_ASSERT(exp)
40
41#else
42
43/*
44 * NDEBUG = NOT defined = Build is on Debug
45 * Define AZURE_ASSERT to call assert to provide better debug experience.
46 */
47
48#include <cassert>
49
51#define AZURE_ASSERT(exp) assert((exp))
53#define AZURE_ASSERT_MSG(exp, msg) assert(((void)msg, (exp)))
54
55#endif
56
57namespace Azure { namespace Core { namespace _internal {
58 [[noreturn]] void AzureNoReturnPath(std::string const& msg);
59}}} // namespace Azure::Core::_internal
60
62#define AZURE_ASSERT_FALSE(exp) AZURE_ASSERT(!(exp))
64#define AZURE_UNREACHABLE_CODE() ::Azure::Core::_internal::AzureNoReturnPath("unreachable code!")
66#define AZURE_NOT_IMPLEMENTED() ::Azure::Core::_internal::AzureNoReturnPath("not implemented code!")
67
68#if __cplusplus >= 201703L
69// C++17 or later - use [[nodiscard]].
71#define _azure_NODISCARD [[nodiscard]]
72#else
73#if defined(_MSC_VER)
74// MSVC >= 1911, use [[nodiscard]]
75#if _MSC_VER >= 1911
77#define _azure_NODISCARD [[nodiscard]]
78#else
79// MSVC < 1911, use _Check_return_
80#define _azure_NODISCARD _Check_return_
81#endif
82#elif defined(__GNUC__) && __GNUC__ >= 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
83// GCC 3.4 or higher, use __attribute__((warn_unused_result)).
85#define _azure_NODISCARD __attribute__((__warn_unused_result__))
86#elif defined(__clang__)
88#define _azure_NODISCARD __attribute__(__warn_unused_result__)
89#else
91#define _azure_NODISCARD
92#endif
93#endif // __cplusplus >= 201703L
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
Platform-specific macros.