This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 385331185a GH-15237: [C++] Add ::arrow::Unreachable() using
std::string_view (#15238)
385331185a is described below
commit 385331185ac96b5a20a81b2c5de82158a2641af8
Author: mwish <[email protected]>
AuthorDate: Sun Jan 8 11:22:59 2023 +0800
GH-15237: [C++] Add ::arrow::Unreachable() using std::string_view (#15238)
Here I add a std::string_view `::arrow::Unreachable`, because:
1. `Unreachable(std::string(" a") + "b")` all
`Unreachable(fmt::format(...))` could be easily used
2. non-c-style string can be used.
For api compatibility, I leave the origin `const char*` Unreachable
unchanged.
The cons maybe:
1. abi broken ( Seems no one will use Unreachable like this?)
2. Maybe making compiling a bit slower
* Closes: #15237
Authored-by: mwish <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
---
cpp/src/arrow/util/unreachable.cc | 7 +++++++
cpp/src/arrow/util/unreachable.h | 4 ++++
2 files changed, 11 insertions(+)
diff --git a/cpp/src/arrow/util/unreachable.cc
b/cpp/src/arrow/util/unreachable.cc
index 4ffe3a8f78..a3829d1165 100644
--- a/cpp/src/arrow/util/unreachable.cc
+++ b/cpp/src/arrow/util/unreachable.cc
@@ -19,6 +19,8 @@
#include "arrow/util/logging.h"
+#include <string_view>
+
namespace arrow {
[[noreturn]] void Unreachable(const char* message) {
@@ -26,4 +28,9 @@ namespace arrow {
std::abort();
}
+[[noreturn]] void Unreachable(std::string_view message) {
+ DCHECK(false) << message;
+ std::abort();
+}
+
} // namespace arrow
diff --git a/cpp/src/arrow/util/unreachable.h b/cpp/src/arrow/util/unreachable.h
index 3da0db6f2b..d2e383e714 100644
--- a/cpp/src/arrow/util/unreachable.h
+++ b/cpp/src/arrow/util/unreachable.h
@@ -19,8 +19,12 @@
#include "arrow/util/visibility.h"
+#include <string_view>
+
namespace arrow {
[[noreturn]] ARROW_EXPORT void Unreachable(const char* message =
"Unreachable");
+[[noreturn]] ARROW_EXPORT void Unreachable(std::string_view message);
+
} // namespace arrow