azure-core
azure_assert.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
16 #pragma once
17 
18 #include "azure/core/platform.hpp"
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 
50 #define AZURE_ASSERT(exp) assert((exp))
51 #define AZURE_ASSERT_MSG(exp, msg) assert(((void)msg, (exp)))
52 
53 #endif
54 
55 namespace Azure { namespace Core { namespace _internal {
56  [[noreturn]] void AzureNoReturnPath(std::string const& msg);
57 }}} // namespace Azure::Core::_internal
58 
59 #define AZURE_ASSERT_FALSE(exp) AZURE_ASSERT(!(exp))
60 #define AZURE_UNREACHABLE_CODE() ::Azure::Core::_internal::AzureNoReturnPath("unreachable code!")
61 #define AZURE_NOT_IMPLEMENTED() ::Azure::Core::_internal::AzureNoReturnPath("not implemented code!")
Azure
Azure SDK abstractions.
Definition: azure_assert.hpp:55
platform.hpp
Platform-specific macros.