-
Notifications
You must be signed in to change notification settings - Fork 280
Updated assert to be more descriptive #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated assert to be more descriptive #629
Conversation
adriengivry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this PR!
For this issue, I was thinking of something much simpler.
Overload targets C++20, so having a non-C++20 version isn't necessary here.
I was actually thinking of something much simpler, like:
Assertion.h
/**
* @project: Overload
* @author: Overload Tech.
* @licence: MIT
*/
#pragma once
#include <source_location>
#include <string>
#ifdef NDEBUG
#define OVASSERT(condition, message) static_cast<void>(0)
#else
#define OVASSERT(condition, message) \
static_cast<bool>(condition) ? \
static_cast<void>(0) : \
OvDebug::_Assert(#condition, message, std::source_location::current());
#endif
namespace OvDebug
{
void _Assert(
const char* p_expression,
const std::string_view p_message,
const std::source_location& p_location
);
}Assertion.cpp
/**
* @project: Overload
* @author: Overload Tech.
* @licence: MIT
*/
#include <OvDebug/Assertion.h>
#include <OvDebug/Logger.h>
#include <cassert>
#include <format>
#if defined(_MSC_VER)
# define OV_DEBUG_BREAK() __debugbreak()
#elif defined(__clang__) || defined(__GNUC__)
# define OV_DEBUG_BREAK() __builtin_trap()
#else
# define OV_DEBUG_BREAK() std::abort()
#endif
void OvDebug::_Assert(const char* p_expression, const std::string_view p_message, const std::source_location& p_location)
{
OVLOG_ERROR(std::format(
"Assertion failed: {}\n"
" Expression: {}\n"
" Function: {}\n"
" Location: {}:{}",
p_message, p_expression, p_location.function_name(),
p_location.file_name(), p_location.line()));
OV_DEBUG_BREAK();
}
Which in practice would produce this sort of output:
[ERROR] 2025-12-08_18-42-56 Assertion failed: x must be positive
Expression: x > 0
Function: void OvEditor::Panels::MenuBar::InitializeSettingsMenu()
Location: src/OvEditor/Panels/MenuBar.cpp:107
with a use case like that:
int x = -1;
OVASSERT(x > 0, "x must be positive");|
Okey I am taking care of that now. |
|
You don't need to close the PR, you can just push your changes to your |
|
Oh, okay thanks. I didn't know that |
d37304b to
fdc29a8
Compare
|
I think it is done now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Let's wait for the build machine to validate that it compiles properly on all platform.
Thanks for all the help tho. I will try to contribute this project as much as i can. |
|
@guneshsn1 all checked passed ✅ |
Description
I have updated the Assertion.h and Assertion.cpp files which is located in OvDebug
Related Issue(s)
Fixes #627
Review Guidance
I have changed the old assert type with the std::source_location type which is a new feature that only works in only C++20
Screenshots/GIFs
I don't have any.
Checklist