[gabi++] Fix the default std::unexpected() handler

The default handler for std::unexpected() should delegate the function
call to std::terminate() so that the user-defined terminate handler can
get the chance to run.

This commit fixes:
- tests/device/test-stlport_shared-exception/jni/eh55.cpp
- tests/device/test-stlport_static-exception/jni/eh55.cpp

Change-Id: Ie18de8b8fc78c4af15bb7af569f0c9e9cfdb3514
diff --git a/sources/cxx-stl/gabi++/src/cxxabi_defines.h b/sources/cxx-stl/gabi++/src/cxxabi_defines.h
index a48c7c0..335baa3 100644
--- a/sources/cxx-stl/gabi++/src/cxxabi_defines.h
+++ b/sources/cxx-stl/gabi++/src/cxxabi_defines.h
@@ -316,6 +316,9 @@
 
 namespace __gabixx {
 
+// Default unexpected handler.
+_GABIXX_NORETURN void __default_unexpected(void) _GABIXX_HIDDEN;
+
 // Default terminate handler.
 _GABIXX_NORETURN void __default_terminate(void) _GABIXX_HIDDEN;
 
diff --git a/sources/cxx-stl/gabi++/src/terminate.cc b/sources/cxx-stl/gabi++/src/terminate.cc
index 822752b..7268001 100644
--- a/sources/cxx-stl/gabi++/src/terminate.cc
+++ b/sources/cxx-stl/gabi++/src/terminate.cc
@@ -32,13 +32,21 @@
 namespace {
 
 std::terminate_handler current_terminate = __gabixx::__default_terminate;
-std::unexpected_handler current_unexpected = __gabixx::__default_terminate;
+std::unexpected_handler current_unexpected = __gabixx::__default_unexpected;
 
 }  // namespace
 
 
 namespace __gabixx {
 
+// The default std::unexpected() implementation will delegate to
+// std::terminate() so that the user-defined std::terminate() handler can
+// get the chance to be invoked.
+//
+_GABIXX_NORETURN void __default_unexpected(void) {
+  std::terminate();
+}
+
 // The default std::terminate() implementation will crash the process.
 // This is done to help debugging, i.e.:
 //   - When running the program in a debugger, it's trivial to get
diff --git a/sources/cxx-stl/gabi++/tests/Android.mk b/sources/cxx-stl/gabi++/tests/Android.mk
index 63c0004..3cda291 100644
--- a/sources/cxx-stl/gabi++/tests/Android.mk
+++ b/sources/cxx-stl/gabi++/tests/Android.mk
@@ -43,6 +43,7 @@
 $(call do_test_simple,test_vector3)
 $(call do_test_simple,unexpected_01,-std=c++11)
 $(call do_test_simple,unexpected_02,-std=c++11)
+$(call do_test_simple,unexpected_03)
 $(call do_test_simple,unwind_01)
 $(call do_test_simple,unwind_02)
 $(call do_test_simple,unwind_03)
diff --git a/sources/cxx-stl/gabi++/tests/unexpected_03.cpp b/sources/cxx-stl/gabi++/tests/unexpected_03.cpp
new file mode 100644
index 0000000..cf4d90e
--- /dev/null
+++ b/sources/cxx-stl/gabi++/tests/unexpected_03.cpp
@@ -0,0 +1,19 @@
+#include <cassert>
+#include <cstdlib>
+#include <exception>
+
+void expected_terminate() {
+  exit(0);
+}
+
+int main() {
+  std::set_terminate(expected_terminate);
+  try {
+    std::unexpected();
+    assert(false);
+  } catch (...) {
+    assert(false);
+  }
+  assert(false);
+  return 1;
+}