Date: Tue, 22 Jul 2025 14:38:07 +0200
Another way to use the c_str() member function you've mentioned,
without involving a variable would be:
> void f(const char*);
> wxString mystr( wxS("Hello I'm a monkey") );
> f(mystr.c_str());
So it's not actually a function that requires [[must_store]] for its
result. Similarly, I can imagine that you could bind an
rvalue/forwarding reference to the result of wlock() when passing that
into a function or so.
All that is to say: it's hard to put your finger on what
[[must_store]] actually means. If it means that you can neither
discard the result, nor create a temporary object from it, then
neither of your examples seem like obviously valid use cases. Does
there even exist a valid example?
There's also a question of how to suppress a warning produced by
[[must_store]]. [[nodiscard]] can be easily suppressed by casting to
void, but that [[must_store]] could presumably not be suppressed in
this way, since casting to void is obviously not storing. However,
storing in a variable for the purpose of suppression would always
involve prolonging the lifetime of an otherwise temporary object, and
it feels wrong if you cannot suppress that warning without such
semantic impact.
Anyhow, I think the costs outweigh the benefits here. [[nodiscard]]
has much better cost/benefit.
Jan
without involving a variable would be:
> void f(const char*);
> wxString mystr( wxS("Hello I'm a monkey") );
> f(mystr.c_str());
So it's not actually a function that requires [[must_store]] for its
result. Similarly, I can imagine that you could bind an
rvalue/forwarding reference to the result of wlock() when passing that
into a function or so.
All that is to say: it's hard to put your finger on what
[[must_store]] actually means. If it means that you can neither
discard the result, nor create a temporary object from it, then
neither of your examples seem like obviously valid use cases. Does
there even exist a valid example?
There's also a question of how to suppress a warning produced by
[[must_store]]. [[nodiscard]] can be easily suppressed by casting to
void, but that [[must_store]] could presumably not be suppressed in
this way, since casting to void is obviously not storing. However,
storing in a variable for the purpose of suppression would always
involve prolonging the lifetime of an otherwise temporary object, and
it feels wrong if you cannot suppress that warning without such
semantic impact.
Anyhow, I think the costs outweigh the benefits here. [[nodiscard]]
has much better cost/benefit.
Jan
Received on 2025-07-22 12:38:27