Skip to content

Commit d7cb138

Browse files
committed
Add check for valueless_by_exception to visit()
1 parent 5301e21 commit d7cb138

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

include/nonstd/variant.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,11 @@ inline void swap(
11151115
template< class Visitor, class Variant >
11161116
inline Variant visit( Visitor const & vis, Variant const & v )
11171117
{
1118+
if ( v.valueless_by_exception() )
1119+
{
1120+
throw bad_variant_access();
1121+
}
1122+
11181123
switch( v.index() )
11191124
{
11201125
case 0: return vis( get<0>( v ) );
@@ -1124,7 +1129,7 @@ inline Variant visit( Visitor const & vis, Variant const & v )
11241129
case 4: return vis( get<4>( v ) );
11251130
case 5: return vis( get<5>( v ) );
11261131
case 6: return vis( get<6>( v ) );
1127-
default: return vis( get<0>( v ) );
1132+
default: return Variant();
11281133
}
11291134
}
11301135

0 commit comments

Comments
 (0)