aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-09-25 15:59:16 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2018-09-25 15:59:16 +0100
commit16d30bbd4dae88ceb08bf8b965c8fd61b25b558c (patch)
tree8e0042be0f57004e04a37b31814ddd8dedeea26d
parent4fb792e189c183aa499e834d9cdc4b3ee3bd064a (diff)
downloadgcc-16d30bbd4dae88ceb08bf8b965c8fd61b25b558c.zip
gcc-16d30bbd4dae88ceb08bf8b965c8fd61b25b558c.tar.gz
gcc-16d30bbd4dae88ceb08bf8b965c8fd61b25b558c.tar.bz2
PR libstdc++/87431 optimise valueless_by_exception()
If a std::variant can never get into valueless state then we don't need to do a runtime check for a valid alternative. PR libstdc++/87431 * include/std/variant (_Variant_storage<true, _Types...>::_M_valid): Avoid runtime test when all alternatives are scalars and so cannot throw during initialization. From-SVN: r264574
-rw-r--r--libstdc++-v3/ChangeLog7
-rw-r--r--libstdc++-v3/include/std/variant2
2 files changed, 9 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index ff53017..67b3eb4 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,10 @@
+2018-09-25 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/87431
+ * include/std/variant (_Variant_storage<true, _Types...>::_M_valid):
+ Avoid runtime test when all alternatives are scalars and so cannot
+ throw during initialization.
+
2018-09-25 Gerald Pfeifer <gerald@pfeifer.com>
* doc/xml/manual/codecvt.xml: Move link to "UTF-8 and Unicode FAQ"
diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant
index 5a77e9e..9289eef 100644
--- a/libstdc++-v3/include/std/variant
+++ b/libstdc++-v3/include/std/variant
@@ -439,6 +439,8 @@ namespace __variant
constexpr bool
_M_valid() const noexcept
{
+ if constexpr ((is_scalar_v<_Types> && ...))
+ return true;
return this->_M_index != __index_type(variant_npos);
}