public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "antoshkka at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/66699] New: Incorrect order of destruction for std::tuple elements
Date: Mon, 29 Jun 2015 21:10:00 -0000	[thread overview]
Message-ID: <bug-66699-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2015-06-29 21:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29 21:10 antoshkka at gmail dot com [this message]
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

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-66699-4@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).