[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 Jonathan Wakely redi at gcc dot gnu.org changed: What|Removed |Added CC||brunonery+bugzilla at ||brunonery dot com --- Comment #16 from Jonathan Wakely redi at gcc dot gnu.org 2012-11-14 11:40:50 UTC --- *** Bug 55318 has been marked as a duplicate of this bug. ***
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 Jonathan Wakely redi at gcc dot gnu.org changed: What|Removed |Added CC||tutufan at gmail dot com --- Comment #15 from Jonathan Wakely redi at gcc dot gnu.org 2011-12-13 19:55:11 UTC --- *** Bug 51533 has been marked as a duplicate of this bug. ***
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 --- Comment #14 from ejb at ql dot org 2011-06-27 18:06:15 UTC --- Very nice to see this bug fixed. :-)
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 --- Comment #12 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-23 08:15:24 UTC --- Author: redi Date: Mon May 23 08:15:16 2011 New Revision: 174058 URL: http://gcc.gnu.org/viewcvs?root=gccview=revrev=174058 Log: 2011-05-23 Jonathan Wakely jwakely@gmail.com PR c++/18016 * init.c (perform_member_init): Check for self-initialization. Added: trunk/gcc/testsuite/g++.dg/warn/pr18016.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/init.c trunk/gcc/testsuite/ChangeLog
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 Jonathan Wakely redi at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED Resolution||FIXED Target Milestone|--- |4.7.0 --- Comment #13 from Jonathan Wakely redi at gcc dot gnu.org 2011-05-23 08:19:38 UTC --- fixed for 4.7.0
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 --- Comment #10 from Manuel López-Ibáñez manu at gcc dot gnu.org 2010-12-22 09:17:42 UTC --- Like others commenting here, I don't understand why a(a) should not warn only with -Winit-self. On the other hand, I always thought that Winit-self is a bad idea. Although the patch does not fixes many cases and thus, we shouldn't close this PR, it is better than nothing. About the location, don't we have a better location at that point? I am thinking that X() : j(j), #2 i(i) #3 {} should give warnings in #2 and #3. Please, resubmit and ping. I think this is small enough to go in GCC 4.6.
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 --- Comment #11 from Jonathan Wakely redi at gcc dot gnu.org 2010-12-22 14:40:07 UTC --- (In reply to comment #10) Like others commenting here, I don't understand why a(a) should not warn only with -Winit-self. I agree with Andrew, the a(a) mistake should always warn, it should be independent of -Winit-self, which exists so that -Wuninitialized doesn't warn about the common (but questionable) practice of self-initializing automatic variables to silence warnings. As I said in my mail to gcc-patches, if you want to leave a member variable uninitialized, just don't give it a mem-initializer in the constructor. Giving it a self-initializing one is just perverse. (The case of automatic variables is different, you can't just not declare it to leave it uninitialized.) Also, as -Winit-self is broken I didn't want to tie this bug to a broken feature that might be changed to not work for C++. On the other hand, I always thought that Winit-self is a bad idea. Although the patch does not fixes many cases and thus, we shouldn't close this PR, it is better than nothing. About the location, don't we have a better location at that point? I am thinking that X() : j(j), #2 i(i) #3 {} should give warnings in #2 and #3. There are various open bugs about that, e.g. PR 43064, I don't think it's possible at the moment.
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 Jonathan Wakely redi at gcc dot gnu.org changed: What|Removed |Added Keywords||patch --- Comment #8 from Jonathan Wakely redi at gcc dot gnu.org 2010-12-21 15:28:18 UTC --- With the patch at http://gcc.gnu.org/ml/gcc-patches/2010-12/msg01622.html the testcase above gives: $ g++4x a.cc -c -Wuninitialized a.cc: In constructor ‘A::A()’: a.cc:4:5: warning: ‘A::a’ is initialized with itself [-Wuninitialized] a.cc: In member function ‘int A::getA()’: a.cc:9:10: warning: ‘b’ is used uninitialized in this function [-Wuninitialized]
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 --- Comment #9 from Jonathan Wakely redi at gcc dot gnu.org 2010-12-21 17:19:57 UTC --- my patch doesn't help in these cases (which clang does warn about): A() : a(this-a) { } A() : a((int)a) { } A() : a(a+1) { } For that we need proper tracking of uninitialized variables, which we don't do for member variables. But my patch catches the simple typo where you accidentally use the wrong variable name in a mem-initializer.
[Bug c++/18016] Warn about member variables initialized with itself
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016 --- Comment #7 from Jonathan Wakely redi at gcc dot gnu.org 2010-12-16 16:05:04 UTC --- (In reply to comment #0) A() : a(a) // -- should generate a warning Clang warns about this with -Wuninitialized My patch for PR 2972 *doesn't* help here, because A::a does have an initializer
[Bug c++/18016] Warn about member variables initialized with itself
--- Comment #6 from manu at gcc dot gnu dot org 2010-02-21 19:17 --- (In reply to comment #5) Is there any chance of activity on this bug? It would be wonderful to have a warning for this case, since these bugs can be extremely annoying to find. -Winit-self is generally broken for C++ (PR 34772). I am not sure what should be solved first. -- manu at gcc dot gnu dot org changed: What|Removed |Added BugsThisDependsOn||34772 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016
[Bug c++/18016] Warn about member variables initialized with itself
--- Comment #5 from irving at cs dot stanford dot edu 2007-04-27 16:45 --- Is there any chance of activity on this bug? It would be wonderful to have a warning for this case, since these bugs can be extremely annoying to find. If the infrastructure supports it, the ideal way to resolve this might be to manually mark all fields of this uninitialized on entry to each constructor. If that's impossible because the dataflow is run only on top level variables, just checking for occurences of :a(a) would help a lot. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016
[Bug c++/18016] Warn about member variables initialized with itself
--- Additional Comments From bangerth at dealii dot org 2004-10-28 13:08 --- That is my view, too. It's an initializer, not an assignment. W. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016
[Bug c++/18016] Warn about member variables initialized with itself
--- Additional Comments From giovannibajo at libero dot it 2004-10-28 03:35 --- -Winit-self has nothing to do with this problem really. in this case :a(a) is equivalent to this-a = this-a; Not really. The member-list syntax is used to *initialize* the members, not to assign a value to them after a default initialization. I think it makes sense to warn only with -Winit-self. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016
[Bug c++/18016] Warn about member variables initialized with itself
--- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-15 17:05 --- -Winit-self has nothing to do with this problem really. in this case :a(a) is equivalent to this-a = this-a; We should warn about this case even without -Winit-self or even -Wuninitialize as we can warn without optimization turned on. Note I added -Winit-self so I know what it was designed to do. -- What|Removed |Added Severity|normal |enhancement Status|UNCONFIRMED |NEW Ever Confirmed||1 Keywords||diagnostic Last reconfirmed|-00-00 00:00:00 |2004-10-15 17:05:57 date|| Summary|-Winit-self misses member |Warn about member variables |variables initialized after |initialized with itself |: in ctor | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18016