* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
@ 2010-12-16 16:05 ` redi at gcc dot gnu.org
2010-12-21 15:28 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2010-12-16 16:05 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
2010-12-16 16:05 ` redi at gcc dot gnu.org
@ 2010-12-21 15:28 ` redi at gcc dot gnu.org
2010-12-21 17:20 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2010-12-21 15:28 UTC (permalink / raw)
To: gcc-bugs
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]
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
2010-12-16 16:05 ` redi at gcc dot gnu.org
2010-12-21 15:28 ` redi at gcc dot gnu.org
@ 2010-12-21 17:20 ` redi at gcc dot gnu.org
2010-12-22 9:18 ` manu at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2010-12-21 17:20 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2010-12-21 17:20 ` redi at gcc dot gnu.org
@ 2010-12-22 9:18 ` manu at gcc dot gnu.org
2010-12-22 14:40 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu.org @ 2010-12-22 9:18 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (3 preceding siblings ...)
2010-12-22 9:18 ` manu at gcc dot gnu.org
@ 2010-12-22 14:40 ` redi at gcc dot gnu.org
2011-05-23 8:39 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2010-12-22 14:40 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (4 preceding siblings ...)
2010-12-22 14:40 ` redi at gcc dot gnu.org
@ 2011-05-23 8:39 ` redi at gcc dot gnu.org
2011-05-23 8:52 ` redi at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-23 8:39 UTC (permalink / raw)
To: gcc-bugs
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=gcc&view=rev&rev=174058
Log:
2011-05-23 Jonathan Wakely <jwakely.gcc@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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (5 preceding siblings ...)
2011-05-23 8:39 ` redi at gcc dot gnu.org
@ 2011-05-23 8:52 ` redi at gcc dot gnu.org
2011-06-27 18:07 ` ejb at ql dot org
` (2 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2011-05-23 8:52 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (6 preceding siblings ...)
2011-05-23 8:52 ` redi at gcc dot gnu.org
@ 2011-06-27 18:07 ` ejb at ql dot org
2011-12-13 19:59 ` redi at gcc dot gnu.org
2012-11-14 11:41 ` redi at gcc dot gnu.org
9 siblings, 0 replies; 15+ messages in thread
From: ejb at ql dot org @ 2011-06-27 18:07 UTC (permalink / raw)
To: gcc-bugs
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. :-)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (7 preceding siblings ...)
2011-06-27 18:07 ` ejb at ql dot org
@ 2011-12-13 19:59 ` redi at gcc dot gnu.org
2012-11-14 11:41 ` redi at gcc dot gnu.org
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2011-12-13 19:59 UTC (permalink / raw)
To: gcc-bugs
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. ***
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c++/18016] Warn about member variables initialized with itself
[not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
` (8 preceding siblings ...)
2011-12-13 19:59 ` redi at gcc dot gnu.org
@ 2012-11-14 11:41 ` redi at gcc dot gnu.org
9 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-14 11:41 UTC (permalink / raw)
To: gcc-bugs
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. ***
^ permalink raw reply [flat|nested] 15+ messages in thread