Date: Fri, 30 Jun 2023 05:41:23 +1000
What's an example of a realistic bug that [[nodiscard_scope]] would catch
but [[nodiscard]] wouldn't?
On Fri, Jun 30, 2023 at 12:46 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> If we want a function's return value not to be discarded, we mark it
> with [[nodiscard]].
>
> In the case of 'std::synchronized_value', the method 'synchronize'
> returns an object that's intended to become a local object, as in:
>
> std::synchronized_value<MyClass> g_obj;
>
> int main(void)
> {
> auto mylock = g_obj.synchronize();
>
> mylock->SomeMethod();
> mylock->SomeOtherMethod();
> }
>
> So maybe we should have a new attribute [[nodiscard_scope]] to
> indicate that the return value should become a local object in the
> calling function.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
but [[nodiscard]] wouldn't?
On Fri, Jun 30, 2023 at 12:46 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> If we want a function's return value not to be discarded, we mark it
> with [[nodiscard]].
>
> In the case of 'std::synchronized_value', the method 'synchronize'
> returns an object that's intended to become a local object, as in:
>
> std::synchronized_value<MyClass> g_obj;
>
> int main(void)
> {
> auto mylock = g_obj.synchronize();
>
> mylock->SomeMethod();
> mylock->SomeOtherMethod();
> }
>
> So maybe we should have a new attribute [[nodiscard_scope]] to
> indicate that the return value should become a local object in the
> calling function.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2023-06-29 19:41:36