public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100721] New: Warn when assigning to temporary
@ 2021-05-21 20:52 davidfromonline at gmail dot com
  2021-05-23 14:27 ` [Bug c++/100721] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: davidfromonline at gmail dot com @ 2021-05-21 20:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100721
           Summary: Warn when assigning to temporary
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: davidfromonline at gmail dot com
  Target Milestone: ---

I would like for there to be a warning that warns for the following code:

```
struct s {};

inline void f() {
        s() = s();
}
```

I know that for a given type, I can prevent this from compiling if I give `s`
an lvalue-refererence-qualified assignment operator, but that requires writing
two assignment operators and two (sometimes three) constructors to get the
behavior I get today from not typing anything, and I have to apply it to every
type. It would be much nicer if I could just turn on a warning for this.

The only valid use case is if your assignment operator has a side effect that
you want.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-27  5:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 20:52 [Bug c++/100721] New: Warn when assigning to temporary davidfromonline at gmail dot com
2021-05-23 14:27 ` [Bug c++/100721] " redi at gcc dot gnu.org
2021-05-23 16:49 ` davidfromonline at gmail dot com
2021-10-27  5:24 ` egallager at gcc dot gnu.org
2021-10-27  5:25 ` egallager at gcc dot gnu.org

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).