[Bug tree-optimization/109801] -Wmaybe-uninitialized warning with -O1 on move constructor
szhong at perforce dot com
gcc-bugzilla@gcc.gnu.org
Thu May 25 22:55:24 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109801
--- Comment #7 from Scott Zhong <szhong at perforce dot com> ---
(In reply to rguenther@suse.de from comment #6)
> > Am 25.05.2023 um 20:24 schrieb pinskia at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109801
> >
> > --- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> > (In reply to Scott Zhong from comment #4)
> >> The move constructor "steals" resources rather than make copies of them, and
> >> leave the argument in some valid but otherwise indeterminate state. It is
> >> reasonable that size_ is not initialized in the context of a move
> >> constructor.
>
> Maybe, but you still copy an uninitialized variable so the diagnostic is
> correct.
If I understand you correctly, the following example should produce an
uninitialized variable diagnostics and the fact that it doesn't means it is a
bug in the compiler?
#include <algorithm>
class table
{
public:
table()
: size_(0) {}
table(table&& other) {
std::swap(size_, other.size_);
}
~table() {}
private:
int size_;
};
int main()
{
table container(std::move(table()));
return (0);
}
More information about the Gcc-bugs
mailing list