* [v3 PATCH] Implement LWG 2806, Base class of bad_optional_access.
@ 2017-03-12 11:47 Ville Voutilainen
2017-03-13 17:28 ` Jonathan Wakely
0 siblings, 1 reply; 2+ messages in thread
From: Ville Voutilainen @ 2017-03-12 11:47 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
Tested on Linux-x64.
2017-03-12 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement LWG 2806, Base class of bad_optional_access.
* include/std/optional (bad_optional_access):
Derive from std::exception.
(bad_optional_access::bad_optional_access): Adjust.
(bad_optional_access::what): New.
(__throw_bad_optional_access(const char*)):
Remove the parameter and adjust calls.
* testsuite/20_util/optional/cons/value_neg.cc: Adjust.
* testsuite/20_util/optional/typedefs.cc: Likewise.
[-- Attachment #2: lwg2806.diff --]
[-- Type: text/plain, Size: 4299 bytes --]
diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional
index c700515..5e796ac 100644
--- a/libstdc++-v3/include/std/optional
+++ b/libstdc++-v3/include/std/optional
@@ -76,25 +76,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* dereferenced.
* @ingroup exceptions
*/
- class bad_optional_access : public logic_error
+ class bad_optional_access : public exception
{
- // XXX See LEWG 72, https://issues.isocpp.org/show_bug.cgi?id=72
public:
- bad_optional_access() : logic_error("bad optional access") { }
- // XXX This constructor is non-standard. Should not be inline
- explicit bad_optional_access(const char* __arg) : logic_error(__arg) { }
+ bad_optional_access() { }
+ virtual const char* what() const noexcept override
+ {return "bad optional access";}
virtual ~bad_optional_access() noexcept = default;
};
void
- __throw_bad_optional_access(const char*)
+ __throw_bad_optional_access()
__attribute__((__noreturn__));
// XXX Does not belong here.
inline void
- __throw_bad_optional_access(const char* __s)
- { _GLIBCXX_THROW_OR_ABORT(bad_optional_access(__s)); }
+ __throw_bad_optional_access()
+ { _GLIBCXX_THROW_OR_ABORT(bad_optional_access()); }
/**
* @brief Class template that holds the necessary state for @ref optional
@@ -669,8 +668,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
return this->_M_is_engaged()
? this->_M_get()
- : (__throw_bad_optional_access("Attempt to access value of a "
- "disengaged optional object"),
+ : (__throw_bad_optional_access(),
this->_M_get());
}
@@ -679,8 +677,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
return this->_M_is_engaged()
? this->_M_get()
- : (__throw_bad_optional_access("Attempt to access value of a "
- "disengaged optional object"),
+ : (__throw_bad_optional_access(),
this->_M_get());
}
@@ -689,8 +686,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
return this->_M_is_engaged()
? std::move(this->_M_get())
- : (__throw_bad_optional_access("Attempt to access value of a "
- "disengaged optional object"),
+ : (__throw_bad_optional_access(),
std::move(this->_M_get()));
}
@@ -699,8 +695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
return this->_M_is_engaged()
? std::move(this->_M_get())
- : (__throw_bad_optional_access("Attempt to access value of a "
- "disengaged optional object"),
+ : (__throw_bad_optional_access(),
std::move(this->_M_get()));
}
diff --git a/libstdc++-v3/testsuite/20_util/optional/cons/value_neg.cc b/libstdc++-v3/testsuite/20_util/optional/cons/value_neg.cc
index c1d652f..249f622 100644
--- a/libstdc++-v3/testsuite/20_util/optional/cons/value_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/cons/value_neg.cc
@@ -37,8 +37,8 @@ int main()
std::optional<std::unique_ptr<int>> oup2 = new int; // { dg-error "conversion" }
struct U { explicit U(std::in_place_t); };
std::optional<U> ou(std::in_place); // { dg-error "no matching" }
- // { dg-error "no type" "" { target { *-*-* } } 438 }
- // { dg-error "no type" "" { target { *-*-* } } 448 }
- // { dg-error "no type" "" { target { *-*-* } } 505 }
+ // { dg-error "no type" "" { target { *-*-* } } 437 }
+ // { dg-error "no type" "" { target { *-*-* } } 447 }
+ // { dg-error "no type" "" { target { *-*-* } } 504 }
}
}
diff --git a/libstdc++-v3/testsuite/20_util/optional/typedefs.cc b/libstdc++-v3/testsuite/20_util/optional/typedefs.cc
index 01b76e8..8d3f997 100644
--- a/libstdc++-v3/testsuite/20_util/optional/typedefs.cc
+++ b/libstdc++-v3/testsuite/20_util/optional/typedefs.cc
@@ -29,5 +29,7 @@ using check2_t = std::in_place_t;
using check3_t = std::nullopt_t;
using check4_t = std::bad_optional_access;
-static_assert(std::is_base_of<std::logic_error, check4_t>::value,
- "bad_optional_access must derive from logic_error");
+static_assert(!std::is_base_of<std::logic_error, check4_t>::value,
+ "bad_optional_access must derive from exception");
+static_assert(std::is_base_of<std::exception, check4_t>::value,
+ "bad_optional_access must derive from exception");
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [v3 PATCH] Implement LWG 2806, Base class of bad_optional_access.
2017-03-12 11:47 [v3 PATCH] Implement LWG 2806, Base class of bad_optional_access Ville Voutilainen
@ 2017-03-13 17:28 ` Jonathan Wakely
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2017-03-13 17:28 UTC (permalink / raw)
To: Ville Voutilainen; +Cc: libstdc++, gcc-patches
On 12/03/17 13:47 +0200, Ville Voutilainen wrote:
>Tested on Linux-x64.
>
>2017-03-12 Ville Voutilainen <ville.voutilainen@gmail.com>
>
> Implement LWG 2806, Base class of bad_optional_access.
> * include/std/optional (bad_optional_access):
> Derive from std::exception.
> (bad_optional_access::bad_optional_access): Adjust.
> (bad_optional_access::what): New.
> (__throw_bad_optional_access(const char*)):
> Remove the parameter and adjust calls.
> * testsuite/20_util/optional/cons/value_neg.cc: Adjust.
> * testsuite/20_util/optional/typedefs.cc: Likewise.
OK, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-13 17:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-12 11:47 [v3 PATCH] Implement LWG 2806, Base class of bad_optional_access Ville Voutilainen
2017-03-13 17:28 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).