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.

Reply via email to