C++ Logo

std-proposals

Advanced search

Re: [std-proposals] New function attribute [[nodiscard_scope]]

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 29 Jun 2023 22:23:47 +0100
On Thu, Jun 29, 2023 at 8:41 PM Andrew Tomazos <andrewtomazos_at_[hidden]> wrote:
>
> What's an example of a realistic bug that [[nodiscard_scope]] would catch but [[nodiscard]] wouldn't?


synchronized_value<MyClass> g_obj;

void Func(void)
{
    auto &myref = *g_obj.synchronize(); // This mistake would be
caught by [[nodiscard_scope]]

    myref.SomeMethod();
}

Received on 2023-06-29 21:24:00