public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression
@ 2011-04-11 21:45 schaub.johannes at googlemail dot com
  2011-04-19  9:20 ` [Bug c++/48562] " amonakov at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-04-11 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Prematurely destroys initializer_list array when using
                    new-expression
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


The C++0x spec requires that GCC destroys the backing-up array at "delete p",
but GCC appears to destroy it immediately after the first declaration (as
checked by using a class type that has a side-effecting destructor). 

    auto *p= new initializer_list<int>{1, 2, 3}; 
    { auto q(*p); }
    delete p;


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

* [Bug c++/48562] Prematurely destroys initializer_list array when using new-expression
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
@ 2011-04-19  9:20 ` amonakov at gcc dot gnu.org
  2011-09-23 22:09 ` [Bug c++/48562] [C++0x] " paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: amonakov at gcc dot gnu.org @ 2011-04-19  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

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

--- Comment #1 from Alexander Monakov <amonakov at gcc dot gnu.org> 2011-04-19 09:20:05 UTC ---
*** Bug 48669 has been marked as a duplicate of this bug. ***


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

* [Bug c++/48562] [C++0x] Prematurely destroys initializer_list array when using new-expression
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
  2011-04-19  9:20 ` [Bug c++/48562] " amonakov at gcc dot gnu.org
@ 2011-09-23 22:09 ` paolo.carlini at oracle dot com
  2011-09-23 22:25 ` [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
            Summary|Prematurely destroys        |[C++0x] Prematurely
                   |initializer_list array when |destroys initializer_list
                   |using new-expression        |array when using
                   |                            |new-expression

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-23 22:01:23 UTC ---
Is this again PR48370, or should be kept separate?


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

* [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
  2011-04-19  9:20 ` [Bug c++/48562] " amonakov at gcc dot gnu.org
  2011-09-23 22:09 ` [Bug c++/48562] [C++0x] " paolo.carlini at oracle dot com
@ 2011-09-23 22:25 ` jason at gcc dot gnu.org
  2011-09-23 22:26 ` paolo.carlini at oracle dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2011-09-23 22:25 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-09-23
            Summary|[C++0x] Prematurely         |[C++0x] warn about uses of
                   |destroys initializer_list   |initializer_list that will
                   |array when using            |lead to dangling pointers
                   |new-expression              |
     Ever Confirmed|0                           |1

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> 2011-09-23 22:13:45 UTC ---
This is related to DR 1290.  At Bloomington we decided to clarify that the
lifetime of the array is like a temporary bound to a reference; in this case it
has full-expression lifetime.  We should probably add a warning about "new
initializer_list".


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

* [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
                   ` (2 preceding siblings ...)
  2011-09-23 22:25 ` [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers jason at gcc dot gnu.org
@ 2011-09-23 22:26 ` paolo.carlini at oracle dot com
  2011-09-23 22:35 ` paolo.carlini at oracle dot com
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 22:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot       |paolo.carlini at oracle dot
                   |gnu.org                     |com

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-23 22:23:04 UTC ---
Ah, Ok, thanks. Let's see what I can do.


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

* [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
                   ` (3 preceding siblings ...)
  2011-09-23 22:26 ` paolo.carlini at oracle dot com
@ 2011-09-23 22:35 ` paolo.carlini at oracle dot com
  2011-09-25 11:08 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 22:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED


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

* [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
                   ` (4 preceding siblings ...)
  2011-09-23 22:35 ` paolo.carlini at oracle dot com
@ 2011-09-25 11:08 ` paolo.carlini at oracle dot com
  2011-09-25 14:53 ` schaub.johannes at googlemail dot com
  2011-09-25 14:58 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-25 11:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-25 10:54:07 UTC ---
Johannes, sorry about the dumb question: now I understand the issue decently
well - and after all boils down to adding a warning - but I'm not sure to
understand your code snippet: is it meant to crash at runtime? Trigger valgrind
errors?


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

* [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
                   ` (5 preceding siblings ...)
  2011-09-25 11:08 ` paolo.carlini at oracle dot com
@ 2011-09-25 14:53 ` schaub.johannes at googlemail dot com
  2011-09-25 14:58 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: schaub.johannes at googlemail dot com @ 2011-09-25 14:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Johannes Schaub <schaub.johannes at googlemail dot com> 2011-09-25 14:22:33 UTC ---
(In reply to comment #5)
> Johannes, sorry about the dumb question: now I understand the issue decently
> well - and after all boils down to adding a warning - but I'm not sure to
> understand your code snippet: is it meant to crash at runtime? Trigger valgrind
> errors?

In the C++11 spec, it is said that the lifetime of the backing-up array is the
same as the lifetime of the initializer_list object which was initialized by
the array (not considering the DRs and their resolution that Jason has pointed
to). My code was just meant to test whether GCC obeys those rules.

struct X {
  X(int) { cout << "+"; }
  X(X const&) { cout << "+"; }
  ~X() { cout << "-"; }
};

auto *p = new initalizer_list<X>{1, 2, 3}; // ... not at this
delete p; // C++11 requires "now" at this point ...

(again not considering those DRs that revise these rules). 

I think that a warning against "({...})" would be useful too

    // fine
    initializer_list<int> a{1, 2, 3};

    // this is bad
    initializer_list<int> b({1, 2, 3});

Second one is bad because it will destroy the array after initializing 'b', and
won't lengthen the lifetime (because it will use the copy/move constructor).


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

* [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers
  2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
                   ` (6 preceding siblings ...)
  2011-09-25 14:53 ` schaub.johannes at googlemail dot com
@ 2011-09-25 14:58 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-25 14:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
         AssignedTo|paolo.carlini at oracle dot |unassigned at gcc dot
                   |com                         |gnu.org

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-25 14:39:07 UTC ---
Ok, thanks. At the moment, I'm not really working on this.


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

end of thread, other threads:[~2011-09-25 14:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-11 21:45 [Bug c++/48562] New: Prematurely destroys initializer_list array when using new-expression schaub.johannes at googlemail dot com
2011-04-19  9:20 ` [Bug c++/48562] " amonakov at gcc dot gnu.org
2011-09-23 22:09 ` [Bug c++/48562] [C++0x] " paolo.carlini at oracle dot com
2011-09-23 22:25 ` [Bug c++/48562] [C++0x] warn about uses of initializer_list that will lead to dangling pointers jason at gcc dot gnu.org
2011-09-23 22:26 ` paolo.carlini at oracle dot com
2011-09-23 22:35 ` paolo.carlini at oracle dot com
2011-09-25 11:08 ` paolo.carlini at oracle dot com
2011-09-25 14:53 ` schaub.johannes at googlemail dot com
2011-09-25 14:58 ` 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).