From f8c14ed8f08bc7896e678cd7225bfe281459b853 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Wed, 26 Oct 2022 13:22:08 -0400 Subject: [PATCH] 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 --- src/include/scope_guard.h | 2 ++ 1 file changed, 2 insertions(+) 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)... }; } -- 2.47.3