浏览代码

Merging r294133 and r294142:
------------------------------------------------------------------------
r294133 | marshall | 2017-02-05 12:06:38 -0800 (Sun, 05 Feb 2017) | 1 line

Change the base class of std::bad_optional_access. This is a (subtle) ABI change, and is in response to http://http://wg21.link/LWG2806, which I *expect* to be adopted in Kona. I am making this change now in anticipation, and will get it into 4.0, because (a) 4.0 is the first release with std::optional, and (b) I don't want to make an ABI-change later, when the user base should be significantly larger. Note that I didn't change std::experimental::bad_optional_access, because that's still specified to derive from std::logic_error.
------------------------------------------------------------------------

------------------------------------------------------------------------
r294142 | marshall | 2017-02-05 12:52:32 -0800 (Sun, 05 Feb 2017) | 1 line

Restore the _NOEXCEPT on the dtor of bad_optional_access. Destructors are noexcept by default, so it's not really needed, but the other exception classes have the _NOEXCEPT, and gcc complains if these are missing. I think we should remove them all - but not today.
------------------------------------------------------------------------


git-svn-id: https://llvm.org/svn/llvm-project/libcxx/branches/release_40@294249 91177308-0d34-0410-b5e6-96231b3b80d8

Hans Wennborg 8 年之前
父节点
当前提交
7f19f83005
共有 3 个文件被更改,包括 9 次插入7 次删除
  1. 2 4
      include/optional
  2. 4 0
      src/optional.cpp
  3. 3 3
      test/std/utilities/optional/optional.bad_optional_access/derive.pass.cpp

+ 2 - 4
include/optional

@@ -160,14 +160,12 @@ namespace std  // purposefully not using versioning namespace
 {
 
 class _LIBCPP_EXCEPTION_ABI bad_optional_access
-    : public logic_error
+    : public exception
 {
 public:
-    _LIBCPP_INLINE_VISIBILITY
-    bad_optional_access() : logic_error("bad optional access") {}
-
     // Get the key function ~bad_optional_access() into the dylib
     virtual ~bad_optional_access() _NOEXCEPT;
+    virtual const char* what() const _NOEXCEPT;
 };
 
 }  // std

+ 4 - 0
src/optional.cpp

@@ -15,6 +15,10 @@ namespace std
 
 bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
 
+const char* bad_optional_access::what() const _NOEXCEPT {
+  return "bad_optional_access";
+  }
+
 } // std
 
 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL

+ 3 - 3
test/std/utilities/optional/optional.bad_optional_access/derive.pass.cpp

@@ -11,7 +11,7 @@
 
 // <optional>
 
-// class bad_optional_access : public logic_error
+// class bad_optional_access : public exception
 
 #include <optional>
 #include <type_traits>
@@ -20,6 +20,6 @@ int main()
 {
     using std::bad_optional_access;
 
-    static_assert(std::is_base_of<std::logic_error, bad_optional_access>::value, "");
-    static_assert(std::is_convertible<bad_optional_access*, std::logic_error*>::value, "");
+    static_assert(std::is_base_of<std::exception, bad_optional_access>::value, "");
+    static_assert(std::is_convertible<bad_optional_access*, std::exception*>::value, "");
 }