This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/66699] New: Incorrect order of destruction for std::tuple elements


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]