public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/63203] New: Self-initialization of reference not diagnosed if it occurs within a loop
@ 2014-09-08  5:23 jzwinck at gmail dot com
  2014-09-08  9:17 ` [Bug c++/63203] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jzwinck at gmail dot com @ 2014-09-08  5:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63203

            Bug ID: 63203
           Summary: Self-initialization of reference not diagnosed if it
                    occurs within a loop
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jzwinck at gmail dot com

The following is nonsensical yet compiles cleanly with "g++ -Wall -Wextra
-Werror -Winit-self" (I tested GCC 4.7.2 and 4.9.0):

#include <iostream>
#include <string>

int main()
{
  for (int ii = 0; ii < 1; ++ii)
  {
    const std::string& str = str; // !!
    std::cout << str << std::endl;
  }
}

The line marked !! results in undefined behavior, yet is not diagnosed by GCC.
However, commenting out the for line makes GCC complain:

    error: ‘str’ is used uninitialized in this function [-Werror=uninitialized]

If you change std::string to int and turn on optimization, GCC will diagnose
the error even with the loop.

Ref:
http://stackoverflow.com/questions/25717740/why-is-gcc-tricked-into-allowing-undefined-behavior-simply-by-putting-it-in-a-lo
>From gcc-bugs-return-461397-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Sep 08 07:10:10 2014
Return-Path: <gcc-bugs-return-461397-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 11378 invoked by alias); 8 Sep 2014 07:10:09 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 11348 invoked by uid 48); 8 Sep 2014 07:10:04 -0000
From: "ville.voutilainen at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/63201] Full specialization of a member variable template of a class template does not work
Date: Mon, 08 Sep 2014 07:10:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: rejects-valid
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ville.voutilainen at gmail dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on everconfirmed
Message-ID: <bug-63201-4-siFVxPH2rK@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63201-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63201-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-09/txt/msg01231.txt.bz2
Content-length: 414

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc201

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-09-08
     Ever confirmed|0                           |1


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

end of thread, other threads:[~2014-11-24 13:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-08  5:23 [Bug c++/63203] New: Self-initialization of reference not diagnosed if it occurs within a loop jzwinck at gmail dot com
2014-09-08  9:17 ` [Bug c++/63203] " redi at gcc dot gnu.org
2014-09-08 10:16 ` redi at gcc dot gnu.org
2014-11-23 20:16 ` paolo.carlini at oracle dot com
2014-11-24 13:35 ` paolo at gcc dot gnu.org
2014-11-24 13:57 ` paolo.carlini at oracle dot com

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