public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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 ` [Bug c++/18016] Warn about member variables initialized with itself 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 ` [Bug c++/18016] Warn about member variables initialized with itself 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

* [Bug c++/18016] Warn about member variables initialized with itself
       [not found] <bug-18016-4042@http.gcc.gnu.org/bugzilla/>
  2007-04-27 15:45 ` irving at cs dot stanford dot edu
@ 2010-02-21 19:17 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 15+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21 19:17 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/18016] Warn about member variables initialized with itself
       [not found] <bug-18016-4042@http.gcc.gnu.org/bugzilla/>
@ 2007-04-27 15:45 ` irving at cs dot stanford dot edu
  2010-02-21 19:17 ` manu at gcc dot gnu dot org
  1 sibling, 0 replies; 15+ messages in thread
From: irving at cs dot stanford dot edu @ 2007-04-27 15:45 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/18016] Warn about member variables initialized with itself
  2004-10-15 16:45 [Bug c++/18016] New: -Winit-self misses member variables initialized after : in ctor ejb at ql dot org
  2004-10-15 17:05 ` [Bug c++/18016] Warn about member variables initialized with itself pinskia at gcc dot gnu dot org
  2004-10-28  3:35 ` giovannibajo at libero dot it
@ 2004-10-28 13:08 ` bangerth at dealii dot org
  2 siblings, 0 replies; 15+ messages in thread
From: bangerth at dealii dot org @ 2004-10-28 13:08 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/18016] Warn about member variables initialized with itself
  2004-10-15 16:45 [Bug c++/18016] New: -Winit-self misses member variables initialized after : in ctor ejb at ql dot org
  2004-10-15 17:05 ` [Bug c++/18016] Warn about member variables initialized with itself pinskia at gcc dot gnu dot org
@ 2004-10-28  3:35 ` giovannibajo at libero dot it
  2004-10-28 13:08 ` bangerth at dealii dot org
  2 siblings, 0 replies; 15+ messages in thread
From: giovannibajo at libero dot it @ 2004-10-28  3:35 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/18016] Warn about member variables initialized with itself
  2004-10-15 16:45 [Bug c++/18016] New: -Winit-self misses member variables initialized after : in ctor ejb at ql dot org
@ 2004-10-15 17:05 ` pinskia at gcc dot gnu dot org
  2004-10-28  3:35 ` giovannibajo at libero dot it
  2004-10-28 13:08 ` bangerth at dealii dot org
  2 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-15 17:05 UTC (permalink / raw)
  To: gcc-bugs


------- 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|0000-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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2012-11-14 11:41 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-18016-4@http.gcc.gnu.org/bugzilla/>
2010-12-16 16:05 ` [Bug c++/18016] Warn about member variables initialized with itself 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
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
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
     [not found] <bug-18016-4042@http.gcc.gnu.org/bugzilla/>
2007-04-27 15:45 ` irving at cs dot stanford dot edu
2010-02-21 19:17 ` manu at gcc dot gnu dot org
2004-10-15 16:45 [Bug c++/18016] New: -Winit-self misses member variables initialized after : in ctor ejb at ql dot org
2004-10-15 17:05 ` [Bug c++/18016] Warn about member variables initialized with itself pinskia at gcc dot gnu dot org
2004-10-28  3:35 ` giovannibajo at libero dot it
2004-10-28 13:08 ` bangerth at dealii dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).