public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue
@ 2012-08-30 23:08 mrks at koios dot de
  2014-03-28 14:15 ` [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early tclamb at ufl dot edu
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: mrks at koios dot de @ 2012-08-30 23:08 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54430
           Summary: [C++11] Range Based For Loop lhs scoping issue
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mrks@koios.de


The scope of the iterating variable begins too early, i.e. it is already
available in the expression of the rhs.
This is a problem if the rhs expression includes the same identifier which is
shadowed by this issue.

Simple case:
  int i[] = { };
  for (int i : i);

fails to compile because the rhs 'i' will be the same as the lhs 'i' which is
not a valid expression for the range-based for-loop.

The range-based for-loop is equivalent to some for-construct. According to the
standard the above should compile because the scope of the lhs begins inside
the body of this substituted for-loop.


Just for completeness: The Evil case:
  class MyType {
    std::vector<MyType*> vec;
  public:
    const std::vector<MyType*>& foo() { return vec; }
  };

  MyType * t = new MyType;
  for (MyType * t : t->foo());

this will not refuse to compile since everything is well-formed. The real
problem is that foo isn't called on the previously defined t but on the new
uninitialized t.


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
@ 2014-03-28 14:15 ` tclamb at ufl dot edu
  2014-03-28 14:16 ` ppluzhnikov at google dot com
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: tclamb at ufl dot edu @ 2014-03-28 14:15 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Lamb <tclamb at ufl dot edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tclamb at ufl dot edu

--- Comment #1 from Thomas Lamb <tclamb at ufl dot edu> ---
Just hit this bug in GCC 4.9. Again, the lhs side has scope before the rhs has
been evaluated, which is against the standardese in section 6.5.4 of both N3936
and N3291.


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
  2014-03-28 14:15 ` [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early tclamb at ufl dot edu
@ 2014-03-28 14:16 ` ppluzhnikov at google dot com
  2014-03-28 14:17 ` ppluzhnikov at google dot com
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at google dot com @ 2014-03-28 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Pluzhnikov <ppluzhnikov at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppluzhnikov at google dot com

--- Comment #2 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
*** Bug 57493 has been marked as a duplicate of this bug. ***


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
  2014-03-28 14:15 ` [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early tclamb at ufl dot edu
  2014-03-28 14:16 ` ppluzhnikov at google dot com
@ 2014-03-28 14:17 ` ppluzhnikov at google dot com
  2014-03-28 17:29 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: ppluzhnikov at google dot com @ 2014-03-28 14:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
>From PR57493: Google ref: b/9229787


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (2 preceding siblings ...)
  2014-03-28 14:17 ` ppluzhnikov at google dot com
@ 2014-03-28 17:29 ` redi at gcc dot gnu.org
  2015-08-09  7:49 ` akim.demaille at gmail dot com
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-03-28 17:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-03-28
     Ever confirmed|0                           |1


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (3 preceding siblings ...)
  2014-03-28 17:29 ` redi at gcc dot gnu.org
@ 2015-08-09  7:49 ` akim.demaille at gmail dot com
  2015-08-09  7:51 ` akim.demaille at gmail dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: akim.demaille at gmail dot com @ 2015-08-09  7:49 UTC (permalink / raw)
  To: gcc-bugs

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

Akim Demaille <akim.demaille at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |akim.demaille at gmail dot com

--- Comment #4 from Akim Demaille <akim.demaille at gmail dot com> ---
I hit that one too with 5.2.


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (4 preceding siblings ...)
  2015-08-09  7:49 ` akim.demaille at gmail dot com
@ 2015-08-09  7:51 ` akim.demaille at gmail dot com
  2015-08-17  0:52 ` miyuki at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: akim.demaille at gmail dot com @ 2015-08-09  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Akim Demaille <akim.demaille at gmail dot com> ---
FWIW, it's on StackOverflow since May 2013.

http://stackoverflow.com/questions/16407212/identifier-with-the-same-name-in-both-expression-and-declaration-of-range-based


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (5 preceding siblings ...)
  2015-08-09  7:51 ` akim.demaille at gmail dot com
@ 2015-08-17  0:52 ` miyuki at gcc dot gnu.org
  2015-09-15 10:16 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: miyuki at gcc dot gnu.org @ 2015-08-17  0:52 UTC (permalink / raw)
  To: gcc-bugs

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

Mikhail Maltsev <miyuki at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bloerwald at googlemail dot com

--- Comment #6 from Mikhail Maltsev <miyuki at gcc dot gnu.org> ---
*** Bug 65201 has been marked as a duplicate of this bug. ***


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (6 preceding siblings ...)
  2015-08-17  0:52 ` miyuki at gcc dot gnu.org
@ 2015-09-15 10:16 ` redi at gcc dot gnu.org
  2015-10-01 19:22 ` ville at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2015-09-15 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tony at becrux dot com

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 67584 has been marked as a duplicate of this bug. ***


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (7 preceding siblings ...)
  2015-09-15 10:16 ` redi at gcc dot gnu.org
@ 2015-10-01 19:22 ` ville at gcc dot gnu.org
  2015-10-01 19:24 ` ville.voutilainen at gmail dot com
  2015-10-05  8:53 ` paolo.carlini at oracle dot com
  10 siblings, 0 replies; 12+ messages in thread
From: ville at gcc dot gnu.org @ 2015-10-01 19:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from ville at gcc dot gnu.org ---
Author: ville
Date: Thu Oct  1 19:22:08 2015
New Revision: 228354

URL: https://gcc.gnu.org/viewcvs?rev=228354&root=gcc&view=rev
Log:
PR c++/54430

/cp
2015-10-01  Ville Voutilainen  <ville.voutilainen@gmail.com>

        PR c++/54430
        * name-lookup.c (push_binding): Make non-static.
        * name-lookup.h (push_binding): Declare it.
        * parser.c (cp_parser_range_for): Use it, get the range
        declaration away from the scope until the range expression
        has been parsed, then restore the declaration.

/testsuite
2015-10-01  Ville Voutilainen  <ville.voutilainen@gmail.com>

        PR c++/54430
        * g++.dg/cpp0x/range-for30.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/range-for30.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/cp/name-lookup.h
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (8 preceding siblings ...)
  2015-10-01 19:22 ` ville at gcc dot gnu.org
@ 2015-10-01 19:24 ` ville.voutilainen at gmail dot com
  2015-10-05  8:53 ` paolo.carlini at oracle dot com
  10 siblings, 0 replies; 12+ messages in thread
From: ville.voutilainen at gmail dot com @ 2015-10-01 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |ville.voutilainen at gmail dot com
         Resolution|---                         |FIXED

--- Comment #9 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
Fixed on trunk.


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

* [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early
  2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
                   ` (9 preceding siblings ...)
  2015-10-01 19:24 ` ville.voutilainen at gmail dot com
@ 2015-10-05  8:53 ` paolo.carlini at oracle dot com
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-10-05  8:53 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |6.0


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

end of thread, other threads:[~2015-10-05  8:53 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-30 23:08 [Bug c++/54430] New: [C++11] Range Based For Loop lhs scoping issue mrks at koios dot de
2014-03-28 14:15 ` [Bug c++/54430] [C++11] For-Loop: Scope of iterating variable begins too early tclamb at ufl dot edu
2014-03-28 14:16 ` ppluzhnikov at google dot com
2014-03-28 14:17 ` ppluzhnikov at google dot com
2014-03-28 17:29 ` redi at gcc dot gnu.org
2015-08-09  7:49 ` akim.demaille at gmail dot com
2015-08-09  7:51 ` akim.demaille at gmail dot com
2015-08-17  0:52 ` miyuki at gcc dot gnu.org
2015-09-15 10:16 ` redi at gcc dot gnu.org
2015-10-01 19:22 ` ville at gcc dot gnu.org
2015-10-01 19:24 ` ville.voutilainen at gmail dot com
2015-10-05  8:53 ` 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).