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
This commit is contained in:
Jonathan Wakely 2018-09-25 15:59:16 +01:00 committed by Jonathan Wakely
parent 4fb792e189
commit 16d30bbd4d
2 changed files with 9 additions and 0 deletions

View 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"

View 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);
}