public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "miles at gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53287] New: "self-initialization" warning doesn't seem to work for non-primitive types...
Date: Wed, 09 May 2012 00:04:00 -0000	[thread overview]
Message-ID: <bug-53287-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53287

             Bug #: 53287
           Summary: "self-initialization" warning doesn't seem to work for
                    non-primitive types...
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: miles@gnu.org


Gcc has a warning "-Winit-self" which is supposed to warn about cases like "int
x = x;"

It seems to work properly for primitive types, but emits no warnings for
classes.

E.g., the following:

    struct S { S (); S (const S &); int i; };

    extern void g (const S &);

    void f ()
    {
      S x = x;
      g (x);
    }

compiles without warnings:

    $ g++-snapshot -c x.cc -O2 -Wall -Wextra -Winit-self
    $ g++-snapshot --version
    g++ (Debian 20120501-1) 4.8.0 20120501 (experimental) [trunk revision
187013]

Replacing the definition of "S" with "typedef int S;", results in the expected
warning: "warning: 'x' is used uninitialized in this function
[-Wuninitialized]", although the warning-flag referenced in the message
("-Wuninitialized") seems a bit odd, as it's clearly -Winit-self that controls
this -- removing -Winit-self from the command-line (but keeping -Wall and
-Wextra) eliminates the warning...

Thanks,

-miles


             reply	other threads:[~2012-05-09  0:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-09  0:04 miles at gnu dot org [this message]
2012-05-09 10:53 ` [Bug c++/53287] " manu at gcc dot gnu.org
2012-05-09 15:59 ` redi at gcc dot gnu.org
2012-10-25  9:15 ` manu at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53287-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).