From 16d30bbd4dae88ceb08bf8b965c8fd61b25b558c Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 25 Sep 2018 15:59:16 +0100 Subject: [PATCH] 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::_M_valid): Avoid runtime test when all alternatives are scalars and so cannot throw during initialization. From-SVN: r264574 --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/include/std/variant | 2 ++ 2 files changed, 9 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ff5301774c7..67b3eb4a94e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2018-09-25 Jonathan Wakely + + PR libstdc++/87431 + * include/std/variant (_Variant_storage::_M_valid): + Avoid runtime test when all alternatives are scalars and so cannot + throw during initialization. + 2018-09-25 Gerald Pfeifer * 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 5a77e9e2d84..9289eef28cf 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); } -- 2.30.2