This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/66699] New: Incorrect order of destruction for std::tuple elements
- From: "antoshkka at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 29 Jun 2015 21:10:10 +0000
- Subject: [Bug libstdc++/66699] New: Incorrect order of destruction for std::tuple elements
- Auto-submitted: auto-generated
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.