public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined
@ 2010-10-17 13:58 alserkli at inbox dot ru
  2010-10-17 16:26 ` [Bug c++/46056] [C++0x] " paolo.carlini at oracle dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: alserkli at inbox dot ru @ 2010-10-17 13:58 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: range-based for loop inside lambda crashes if
                    _GLIBCXX_DEBUG is defined
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: alserkli@inbox.ru
            Target: i686-pc-linux-gnu


The following test crashes once compiled by
g++ (GCC) 4.6.0 20101017 (experimental) on i686-pc-linux-gnu

// Test for range-based for loop inside lambda
// { dg-options "-std=c++0x" }
// { dg-do run }
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
int main(){
  std::vector<int> v(1);
  [&]() { for(auto i: v); }();
}

Apparently it crashes during safe sequence destruction once main is finished.
It does work (i.e., does not crash) without any one of _GLIBCXX_DEBUG, lambda,
or range-based for. Also, it does not crash if optimization is on (e.g., with
-O).


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

* [Bug c++/46056] [C++0x] range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
@ 2010-10-17 16:26 ` paolo.carlini at oracle dot com
  2010-10-19 18:22 ` alserkli at inbox dot ru
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-17 16:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-17 16:25:50 UTC ---
I have big troubles debugging this at the library level only, I suspect the
internal details of the range-based loop (and lambda maybe) are involved.
Adding Jason in CC...


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

* [Bug c++/46056] [C++0x] range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
  2010-10-17 16:26 ` [Bug c++/46056] [C++0x] " paolo.carlini at oracle dot com
@ 2010-10-19 18:22 ` alserkli at inbox dot ru
  2010-10-19 18:24 ` [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators alserkli at inbox dot ru
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: alserkli at inbox dot ru @ 2010-10-19 18:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Alexander Klimov <alserkli at inbox dot ru> 2010-10-19 18:22:11 UTC ---
Created attachment 22086
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22086
simple testcase


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
  2010-10-17 16:26 ` [Bug c++/46056] [C++0x] " paolo.carlini at oracle dot com
  2010-10-19 18:22 ` alserkli at inbox dot ru
@ 2010-10-19 18:24 ` alserkli at inbox dot ru
  2010-10-19 20:35 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: alserkli at inbox dot ru @ 2010-10-19 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

Alexander Klimov <alserkli at inbox dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[C++0x] range-based for     |[C++0x] range-based for
                   |loop inside lambda crashes  |loop does not destruct
                   |if _GLIBCXX_DEBUG is        |iterators
                   |defined                     |

--- Comment #3 from Alexander Klimov <alserkli at inbox dot ru> 2010-10-19 18:24:27 UTC ---
Apparently it has nothing to do with _GLIBCXX_DEBUG or lambda. Turns out
range-based for loop does not call destructor for iterator and thus
v._M_iterators is not null. 

See attachment for a direct testcase.


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (2 preceding siblings ...)
  2010-10-19 18:24 ` [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators alserkli at inbox dot ru
@ 2010-10-19 20:35 ` paolo.carlini at oracle dot com
  2010-10-19 20:49 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-19 20:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-19 20:35:01 UTC ---
Many thanks Alexander.


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (3 preceding siblings ...)
  2010-10-19 20:35 ` paolo.carlini at oracle dot com
@ 2010-10-19 20:49 ` paolo.carlini at oracle dot com
  2010-10-20  8:56 ` rodrigorivascosta at gmail dot com
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-19 20:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-19 20:48:59 UTC ---
Let's add Rodrigo in CC.


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (4 preceding siblings ...)
  2010-10-19 20:49 ` paolo.carlini at oracle dot com
@ 2010-10-20  8:56 ` rodrigorivascosta at gmail dot com
  2010-10-20 10:06 ` rodrigorivascosta at gmail dot com
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rodrigorivascosta at gmail dot com @ 2010-10-20  8:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Rodrigo Rivas <rodrigorivascosta at gmail dot com> 2010-10-20 08:56:30 UTC ---
Ok, thank you for the report...
It looks like the range-for temporary completely ignore destructors.

Also, if the range is a temporary it gets destructed quite early, instead of
being kept alive because of the implicit reference.

for (auto x : temp() )
//the temporary is destroyed here
{
   //...
} //instead of here

It shouldn't be too difficult to patch, though, so I'll try and have a patch in
a while...


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (5 preceding siblings ...)
  2010-10-20  8:56 ` rodrigorivascosta at gmail dot com
@ 2010-10-20 10:06 ` rodrigorivascosta at gmail dot com
  2010-10-20 14:13 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rodrigorivascosta at gmail dot com @ 2010-10-20 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Rodrigo Rivas <rodrigorivascosta at gmail dot com> 2010-10-20 10:06:39 UTC ---
I've just sent a patch to gcc-patches:
http://gcc.gnu.org/ml/gcc-patches/2010-10/msg01699.html

In the testcase I added a lot of other destructor checks, just to be sure.


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (6 preceding siblings ...)
  2010-10-20 10:06 ` rodrigorivascosta at gmail dot com
@ 2010-10-20 14:13 ` jason at gcc dot gnu.org
  2010-10-20 14:19 ` alserkli at inbox dot ru
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2010-10-20 14:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2010-10-20 14:13:44 UTC ---
Author: jason
Date: Wed Oct 20 14:13:38 2010
New Revision: 165726

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=165726
Log:
    PR c++/46056
    * parser.c (cp_convert_range_for): Call cp_finish_decl
    instead of finish_expr_stmt.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/range-for7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (7 preceding siblings ...)
  2010-10-20 14:13 ` jason at gcc dot gnu.org
@ 2010-10-20 14:19 ` alserkli at inbox dot ru
  2010-10-31 10:10 ` paolo.carlini at oracle dot com
  2010-10-31 10:11 ` paolo.carlini at oracle dot com
  10 siblings, 0 replies; 12+ messages in thread
From: alserkli at inbox dot ru @ 2010-10-20 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

Alexander Klimov <alserkli at inbox dot ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #22086|0                           |1
        is obsolete|                            |

--- Comment #9 from Alexander Klimov <alserkli at inbox dot ru> 2010-10-20 14:19:23 UTC ---
Created attachment 22094
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22094
simple testcase

Your patch seems to work, thanks!

Btw, the original "simple testcase" did not contain

  It(const It&){ ++it_counter; }

and thus would fail (It() is called twice, while ~It() -- thrice).


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (8 preceding siblings ...)
  2010-10-20 14:19 ` alserkli at inbox dot ru
@ 2010-10-31 10:10 ` paolo.carlini at oracle dot com
  2010-10-31 10:11 ` paolo.carlini at oracle dot com
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-31 10:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-31 10:10:34 UTC ---
So this is fixed.


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

* [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators
  2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
                   ` (9 preceding siblings ...)
  2010-10-31 10:10 ` paolo.carlini at oracle dot com
@ 2010-10-31 10:11 ` paolo.carlini at oracle dot com
  10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2010-10-31 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.6.0

--- Comment #11 from Paolo Carlini <paolo.carlini at oracle dot com> 2010-10-31 10:10:56 UTC ---
So this is fixed.


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

end of thread, other threads:[~2010-10-31 10:11 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-17 13:58 [Bug c++/46056] New: range-based for loop inside lambda crashes if _GLIBCXX_DEBUG is defined alserkli at inbox dot ru
2010-10-17 16:26 ` [Bug c++/46056] [C++0x] " paolo.carlini at oracle dot com
2010-10-19 18:22 ` alserkli at inbox dot ru
2010-10-19 18:24 ` [Bug c++/46056] [C++0x] range-based for loop does not destruct iterators alserkli at inbox dot ru
2010-10-19 20:35 ` paolo.carlini at oracle dot com
2010-10-19 20:49 ` paolo.carlini at oracle dot com
2010-10-20  8:56 ` rodrigorivascosta at gmail dot com
2010-10-20 10:06 ` rodrigorivascosta at gmail dot com
2010-10-20 14:13 ` jason at gcc dot gnu.org
2010-10-20 14:19 ` alserkli at inbox dot ru
2010-10-31 10:10 ` paolo.carlini at oracle dot com
2010-10-31 10:11 ` 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).