]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include: Add [[nodiscard]] to make_scope_guard 48633/head
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 26 Oct 2022 17:22:08 +0000 (13:22 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 26 Oct 2022 17:33:44 +0000 (13:33 -0400)
To prevent a bug where an unassigned scope guard runs right away.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/include/scope_guard.h

index 878d8c169f5a34d6114fa39d74df1bad0c0e7e05..eacc65e7b6713696d0a8e491a927654c8eb8fc60 100644 (file)
@@ -35,11 +35,13 @@ struct scope_guard {
 };
 
 template <typename F>
+[[nodiscard("Unassigned scope guards will execute immediately")]]
 scope_guard<F> make_scope_guard(F &&f) {
   return scope_guard<F>(std::forward<F>(f));
 }
 
 template<typename F, typename... Args>
+[[nodiscard("Unassigned scope guards will execute immediately")]]
 scope_guard<F> make_scope_guard(std::in_place_type_t<F>, Args&& ...args) {
   return { std::in_place, std::forward<Args>(args)... };
 }