public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/66699] New: Incorrect order of destruction for std::tuple elements
@ 2015-06-29 21:10 antoshkka at gmail dot com
  2015-06-29 21:34 ` [Bug libstdc++/66699] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: antoshkka at gmail dot com @ 2015-06-29 21:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66699
           Summary: Incorrect order of destruction for std::tuple elements
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antoshkka at gmail dot com
  Target Milestone: ---

According to C++ Standard:
"An instantiation of tuple with two arguments is similar to an instantiation of
pair with the same two arguments."

The following small example prints the order of tuple and pair elements
destruction:

#include <tuple>
#include <iostream>

struct print_num {
    int num_;
    ~print_num() {
        std::cerr << num_;
    }
};


int main() {
    {
        std::cerr << "pair : ";
        std::pair<print_num, print_num> p;
        std::get<0>(p).num_ = 0;
        std::get<1>(p).num_ = 1;
    }

    {
        std::cerr << "\ntuple: ";
        std::tuple<print_num, print_num> t;
        std::get<0>(t).num_ = 0;
        std::get<1>(t).num_ = 1;
    }
}

Program outputs
pair : 10
tuple: 01


It seems that destruction of a tuple from last to first element is more correct
than the current approach with destruction from the first element to last.


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

end of thread, other threads:[~2015-06-30 17:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-29 21:10 [Bug libstdc++/66699] New: Incorrect order of destruction for std::tuple elements antoshkka at gmail dot com
2015-06-29 21:34 ` [Bug libstdc++/66699] " pinskia at gcc dot gnu.org
2015-06-30  3:09 ` msebor at gcc dot gnu.org
2015-06-30  5:36 ` antoshkka at gmail dot com
2015-06-30 16:47 ` msebor at gcc dot gnu.org
2015-06-30 17:00 ` redi at gcc dot gnu.org
2015-06-30 17:06 ` redi at gcc dot gnu.org

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