]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR libstdc++/87431 optimise valueless_by_exception()
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Sep 2018 14:59:16 +0000 (14:59 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 25 Sep 2018 14:59:16 +0000 (14:59 +0000)
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@264574 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/variant

index ff5301774c7fefca32d430e215282f4bdd63d21c..67b3eb4a94eb7428bc53ceef94675c07cb3c041e 100644 (file)
@@ -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"
index 5a77e9e2d842a0ae46e186565d60450152da2bff..9289eef28cf61717da3b61732973cb3196c11e3b 100644 (file)
@@ -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);
       }