Skip to content

Commit 86b6dfc

Browse files
authored
[libc++] Fix Coverity warning about use-after-move (#78780)
While the code is technically correct because the index is never actually moved from (and anyway that wouldn't matter since it's an integer), it's still better style not to access an object after it has been moved-from. Since this is so easy to do, just save the index in a temporary variable. rdar://120501577
1 parent cc3fd19 commit 86b6dfc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libcxx/include/variant

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,14 +808,15 @@ protected:
808808
_LIBCPP_HIDE_FROM_ABI static void __generic_construct(__ctor& __lhs, _Rhs&& __rhs) {
809809
__lhs.__destroy();
810810
if (!__rhs.valueless_by_exception()) {
811+
auto __rhs_index = __rhs.index();
811812
__visitation::__base::__visit_alt_at(
812-
__rhs.index(),
813+
__rhs_index,
813814
[](auto& __lhs_alt, auto&& __rhs_alt) {
814815
__construct_alt(__lhs_alt, std::forward<decltype(__rhs_alt)>(__rhs_alt).__value);
815816
},
816817
__lhs,
817818
std::forward<_Rhs>(__rhs));
818-
__lhs.__index = __rhs.index();
819+
__lhs.__index = __rhs_index;
819820
}
820821
}
821822
};

0 commit comments

Comments
 (0)