Bug 100721 - Warn when assigning to temporary
Summary: Warn when assigning to temporary
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: new-warning, new_warning
  Show dependency treegraph
 
Reported: 2021-05-21 20:52 UTC by David Stone
Modified: 2021-10-27 05:25 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-10-27 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Stone 2021-05-21 20:52:18 UTC
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.
Comment 1 David Stone 2021-05-23 16:49:09 UTC
https://bugs.llvm.org/show_bug.cgi?id=50438 is the matching clang bug, so you can coordinate on naming the flag.
Comment 2 Eric Gallager 2021-10-27 05:24:55 UTC
(In reply to David Stone from comment #1)
> https://bugs.llvm.org/show_bug.cgi?id=50438 is the matching clang bug, so
> you can coordinate on naming the flag.

Since it looks like it was confirmed there, I'll confirm it here, too.
Comment 3 Eric Gallager 2021-10-27 05:25:25 UTC
(In reply to Eric Gallager from comment #2)
> (In reply to David Stone from comment #1)
> > https://bugs.llvm.org/show_bug.cgi?id=50438 is the matching clang bug, so
> > you can coordinate on naming the flag.
> 
> Since it looks like it was confirmed there, I'll confirm it here, too.

Oops, but for real this time