public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "maltsevm at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/65201] range-for range-init containing variable named like for-range-declaration iterates over uninitialized for-range-declaration
Date: Tue, 03 Mar 2015 05:00:00 -0000	[thread overview]
Message-ID: <bug-65201-4-DpPNp0siqj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65201-4@http.gcc.gnu.org/bugzilla/>

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

Mikhail Maltsev <maltsevm at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maltsevm at gmail dot com

--- Comment #2 from Mikhail Maltsev <maltsevm at gmail dot com> ---
Reduced testcase, miscompilation, works on clang 3.5.0, but causes segfault on
trunk (r221132) and on g++ 4.8.2 20140120, x86_64-unknown-linux-gnu:

$ cat ./range-for30_r2.cc
struct str
{
    str () : v(0) {}
    str (const str &s) : v(s.v) {}
    ~str () { v = 0; }
    int v;
};

str data[1];

struct vec
{
    str *begin () { return data; }
    str *end () { return data + 1; }
};

vec split (str &s)
{
    s = str();
    return vec();
}

int main ()
{
    str foo;
    for (str &foo : split(foo))
        foo = str();
    return foo.v;
}

And here is an even more minimized testcase (technically it's a different kind
of bug, "accepts invalid") - but I suppose that these bugs are related.

$ cat ./range-for30_r.cc
struct str { };
struct vec {
  str *begin () {}
  str *end () {}
};
vec split (str) {}
int main () {
  for (str foo : split(foo))
    ;
}

Clang rejects this with the following error:
./range-for30_r.cc:8:24: error: use of undeclared identifier 'foo'; did you
mean 'for'?
  for (str foo : split(foo))


  parent reply	other threads:[~2015-03-03  5:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-25 10:33 [Bug c++/65201] New: " bloerwald at googlemail dot com
2015-02-25 10:39 ` [Bug c++/65201] " redi at gcc dot gnu.org
2015-03-03  5:00 ` maltsevm at gmail dot com [this message]
2015-08-17  0:52 ` miyuki 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-65201-4-DpPNp0siqj@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).