From: Adam C. Emerson Date: Wed, 26 Oct 2022 17:22:08 +0000 (-0400) Subject: include: Add [[nodiscard]] to make_scope_guard X-Git-Tag: v18.1.0~952^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F48633%2Fhead;p=ceph.git include: Add [[nodiscard]] to make_scope_guard To prevent a bug where an unassigned scope guard runs right away. Signed-off-by: Adam C. Emerson --- diff --git a/src/include/scope_guard.h b/src/include/scope_guard.h index 878d8c169f5a..eacc65e7b671 100644 --- a/src/include/scope_guard.h +++ b/src/include/scope_guard.h @@ -35,11 +35,13 @@ struct scope_guard { }; template +[[nodiscard("Unassigned scope guards will execute immediately")]] scope_guard make_scope_guard(F &&f) { return scope_guard(std::forward(f)); } template +[[nodiscard("Unassigned scope guards will execute immediately")]] scope_guard make_scope_guard(std::in_place_type_t, Args&& ...args) { return { std::in_place, std::forward(args)... }; }