CppInterOp
C++ Language Interoperability Layer
Loading...
Searching...
No Matches
ErrorInternal.cpp
Go to the documentation of this file.
1//===--- ErrorInternal.cpp - Cpp::Result<T> abort helper --------*- C++ -*-===//
2//
3// Part of the compiler-research project, under the Apache License v2.0 with
4// LLVM Exceptions.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Out-of-line abort for Cpp::Result<T>::value() called on an
10// error-bearing Result. Keeps the inline Result<T> body small.
11//
12// Later PRs extend this file with the boundary translator
13// (llvm::Error / Expected<T> -> Cpp::Result<T>) and per-call
14// diagnostic capture.
15//
16//===----------------------------------------------------------------------===//
17
18#include "CppInterOp/Error.h"
19
21
22#include <cstdio>
23#include <cstdlib>
24
25namespace Cpp {
26
27[[noreturn]] CPPINTEROP_API void
28ResultAbort_ValueOnError(const ErrorRef& /*Err*/) {
29 std::fputs("Cpp::Result<T>::value() called on an error-bearing "
30 "Result. Use value_or(fallback) for lenient semantics, "
31 "or branch on .ok() / .error() before calling .value().\n",
32 stderr);
33 std::abort();
34}
35
36#ifndef NDEBUG
37[[noreturn]] CPPINTEROP_API void
38ResultAbort_UncheckedOnDtor(const ErrorRef& /*Err*/) {
39 std::fputs("Cpp::Result destroyed without check (likely a dropped "
40 "error). Call .ok() / .error() / .value() to inspect, "
41 "or .ignore() to acknowledge.\n",
42 stderr);
43 std::abort();
44}
45#endif
46
47} // namespace Cpp
#define CPPINTEROP_API
Definition Box.h:70
void ResultAbort_UncheckedOnDtor(const ErrorRef &)
void ResultAbort_ValueOnError(const ErrorRef &)