Unify the way that String construction and Vec indexing throw
diff --git a/include/cxx.h b/include/cxx.h
index 786dbb3..d3f6238 100644
--- a/include/cxx.h
+++ b/include/cxx.h
@@ -14,26 +14,6 @@
#include <BaseTsd.h>
#endif
-#ifndef __has_feature
-#define __has_feature(__x) 0
-#endif
-
-#if !__has_feature(cxx_exceptions)
-# define _CXXBRIDGE03_NO_EXCEPTIONS
-#endif
-#if !__EXCEPTIONS
-# define _CXXBRIDGE03_NO_EXCEPTIONS
-#endif
-
-[[noreturn]] inline static void throw_out_of_range(const char *msg) {
-#ifndef _CXXBRIDGE03_NO_EXCEPTIONS
- throw std::out_of_range(msg);
-#else
- ((void)msg);
- std::abort();
-#endif
-}
-
namespace rust {
inline namespace cxxbridge03 {
@@ -303,6 +283,9 @@
////////////////////////////////////////////////////////////////////////////////
/// end public API, begin implementation details
+template <typename Exception>
+void panic [[noreturn]] (const char *msg);
+
template <typename Ret, typename... Args, bool Throws>
Ret Fn<Ret(Args...), Throws>::operator()(Args... args) const noexcept(!Throws) {
return (*this->trampoline)(std::move(args)..., this->fn);
@@ -499,7 +482,7 @@
template <typename T>
const T &Vec<T>::at(size_t n) const {
if (n >= this->size())
- throw_out_of_range("Vec");
+ panic<std::out_of_range>("Vec");
return (*this)[n];
}
diff --git a/src/cxx.cc b/src/cxx.cc
index da05ee2..0fa55b2 100644
--- a/src/cxx.cc
+++ b/src/cxx.cc
@@ -6,16 +6,6 @@
#include <stdexcept>
#include <vector>
-template <typename Exception>
-static void panic [[noreturn]] (const char *msg) {
-#if defined(RUST_CXX_NO_EXCEPTIONS)
- std::cerr << "Error: " << msg << ". Aborting." << std::endl;
- std::terminate();
-#else
- throw Exception(msg);
-#endif
-}
-
extern "C" {
const char *cxxbridge03$cxx_string$data(const std::string &s) noexcept {
return s.data();
@@ -42,6 +32,18 @@
namespace rust {
inline namespace cxxbridge03 {
+template <typename Exception>
+void panic [[noreturn]] (const char *msg) {
+#if defined(RUST_CXX_NO_EXCEPTIONS)
+ std::cerr << "Error: " << msg << ". Aborting." << std::endl;
+ std::terminate();
+#else
+ throw Exception(msg);
+#endif
+}
+
+template void panic<std::out_of_range>(const char *msg);
+
String::String() noexcept { cxxbridge03$string$new(this); }
String::String(const String &other) noexcept {