This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52755] Error on use of implicitly deleted operator=
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 28 Mar 2012 17:39:52 +0000
- Subject: [Bug c++/52755] Error on use of implicitly deleted operator=
- Auto-submitted: auto-generated
- References: <bug-52755-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52755
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-28 17:39:52 UTC ---
(In reply to comment #0)
> Following code compiles fine with every gcc, with every g++ -std=c++98,
> with g++-4.5 -std=c++0x, but not with g++ -std=c++0x (or -std=c++11) since 4.6.
That's because G++ 4.6 was changed to reject your invalid program, it's
supposed to do that, and it means G++ 4.6 is better than G++ 4.5 :)
Isn't the error quite clear?
Assigning t2s needs to use the assignment operator, but that function can't be
implicitly-defined because assigning the volatile member requires
t1s::operator=(const volatile t1s&) which doesn't exist, because the
implicit-declared copy assignment operator has the signature
t1s::operator=(const t1s&)
To fix your code you should either define copy assignment for t1s so it works
on volatile objects, or define assignment for t2s so it doesn't need
t1s::operator= e.g.
t2s& operator=(const t2s& t) { b.a = t.b.a; return *this; }