public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/110363] New: New use-after-move warning
@ 2023-06-22 12:53 antoshkka at gmail dot com
  0 siblings, 0 replies; only message in thread
From: antoshkka at gmail dot com @ 2023-06-22 12:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110363

            Bug ID: 110363
           Summary: New use-after-move warning
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

There's a quite common rule "after the object was moved from it is in the
indeterminate state; it should be either destroyed or a new value should be
assigned to it". The C++ Standard Library follows that rule, many libraries and
companies follow that rule.


Please introduce some '-Wuse-after-move' that warns if the object could be used
after move:


struct resource {
    resource(resource&&) noexcept;
    ~resource();

    void kill_it() && noexcept;
    void should_warn_use_after_move() const & noexcept;
};

void should_warn_use_after_move(resource& r) noexcept;

void do_something(resource r) {
    static_cast<resource&&>(r).kill_it(); // moved out
    should_warn_use_after_move(r);        // warn
    r.should_warn_use_after_move();       // warn
}


Some related request on stackoverflow
https://stackoverflow.com/questions/72532377/g-detect-use-after-stdmove

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-22 12:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-22 12:53 [Bug c++/110363] New: New use-after-move warning antoshkka at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).