Add base::Location support to CHECK_op
This includes cleanup to make it possible to pass
base::Location::Current() only in the case of failure, which is
necessary to have CHECK_op remain working in constexpr contexts.
First the size of Check##name##Impl methods are reduced by having them
only generate the error message on failure (not the LogMessage or
CheckOpResult).
On failure this string can be passed directly into new CheckError
static functions that remove the need for the CheckOpResult type which
is subsequently removed.
Bug: None
Change-Id: I1c3d9f6a49619d13d661a640ec53f42ccbc756ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4519187
Reviewed-by: Lei Zhang <[email protected]>
Commit-Queue: Peter Boström <[email protected]>
Code-Coverage: Findit <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1143108}
diff --git a/base/check.h b/base/check.h
index 89bc33c..4bf8146 100644
--- a/base/check.h
+++ b/base/check.h
@@ -63,16 +63,23 @@
// Class used for raising a check error upon destruction.
class BASE_EXPORT CheckError {
public:
- // Used by CheckOp. Takes ownership of `log_message`.
- explicit CheckError(LogMessage* log_message) : log_message_(log_message) {}
-
static CheckError Check(
const char* condition,
const base::Location& location = base::Location::Current());
+ // Takes ownership over (free()s after using) `log_message_str`, for use with
+ // CHECK_op macros.
+ static CheckError CheckOp(
+ char* log_message_str,
+ const base::Location& location = base::Location::Current());
static CheckError DCheck(
const char* condition,
const base::Location& location = base::Location::Current());
+ // Takes ownership over (free()s after using) `log_message_str`, for use with
+ // DCHECK_op macros.
+ static CheckError DCheckOp(
+ char* log_message_str,
+ const base::Location& location = base::Location::Current());
static CheckError DumpWillBeCheck(
const char* condition,
@@ -108,6 +115,9 @@
}
protected:
+ // Takes ownership of `log_message`.
+ explicit CheckError(LogMessage* log_message) : log_message_(log_message) {}
+
LogMessage* const log_message_;
};