Skip to content

Commit

Permalink
Removes the custom assertion for consistency
Browse files Browse the repository at this point in the history
It's likely that we will desire to replace CRT Report Handler in the DLL
initialization code, for instance.
This would not be affected with the custom debug_assert macro.
  • Loading branch information
CarlosNihelton committed Sep 18, 2023
1 parent 2822203 commit f5e972a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
17 changes: 0 additions & 17 deletions storeapi/base/Exception.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <exception>
#include <format>
#include <iostream>
#include <source_location>
#include <string>
#include <type_traits>
Expand Down Expand Up @@ -78,20 +77,4 @@ class Exception {
}
};

#ifdef NDEBUG
#define debug_assert(expr, msg) ((void)0)
#else // NDEBUG
inline void AssertFail(
std::string_view condition, std::string_view msg,
std::source_location loc = std::source_location::current()) {
std::cerr << std::format(
"[ASSERTION FAILURE]: {}:{} {}\n\tunmet condition: {} ({})\n",
loc.file_name(), loc.line(), loc.function_name(), condition, msg);

std::terminate();
}
#define debug_assert(expr, msg) \
(static_cast<bool>(expr) ? ((void)0) : AssertFail("'" #expr "'", msg))
#endif // NDEBUG

} // namespace StoreApi
8 changes: 4 additions & 4 deletions storeapi/base/impl/StoreContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ StoreContext::Product::CurrentExpirationDate() const {

void StoreContext::Product::PromptUserForPurchase(
PurchaseCallback callback) const {
debug_assert(callback, "callback must have a target function");
assert(callback && "callback must have a target function");
self.RequestPurchaseAsync().Completed(
// The lambda will be called once the RequestPurchaseAsync completes.
[cb = std::move(callback)](
Expand All @@ -68,8 +68,8 @@ void StoreContext::Product::PromptUserForPurchase(
std::vector<StoreContext::Product> StoreContext::GetProducts(
std::span<const std::string> kinds,
std::span<const std::string> ids) const {
debug_assert(!kinds.empty(), "kinds vector cannot be empty");
debug_assert(!ids.empty(), "ids vector cannot be empty");
assert(!kinds.empty() && "kinds vector cannot be empty");
assert(!ids.empty() && "ids vector cannot be empty");
// Gets Microsoft Store listing info for the specified products that are
// associated with the current app. Requires "arrays" of product kinds and
// ids.
Expand Down Expand Up @@ -116,7 +116,7 @@ PurchaseStatus translate(StorePurchaseStatus purchaseStatus) noexcept {
case StorePurchaseStatus::ServerError:
return PurchaseStatus::ServerError;
}
debug_assert(false, "Missing enum elements to translate StorePurchaseStatus.");
assert(false && "Missing enum elements to translate StorePurchaseStatus.");
return StoreApi::PurchaseStatus::Unknown; // To be future proof.
}
} // namespace
Expand Down

0 comments on commit f5e972a

Please sign in to comment.