[Bug c++/49372] New: Temporaries evaluated for arguments of a default constructors of array elements not destructed properly (?)

schaub.johannes at googlemail dot com gcc-bugzilla@gcc.gnu.org
Sat Jun 11 13:27:00 GMT 2011


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

           Summary: Temporaries evaluated for arguments of a default
                    constructors of array elements not destructed properly
                    (?)
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: schaub.johannes@googlemail.com


This testcase outputs a surprising result:

struct A {
  A() { std::cout << "C" << std::endl; }
  ~A() { std::cout << "D" << std::endl; }
};

struct B {
  B(A const& a = A()) { }
};

typedef B array[2];

int main() {
  array{};
}

GCC prints "CCDD". I would have expected "CDCD", as it seems that is the intent
of the wording in the spec (FDIS). The FDIS however seems to be contradicting
here, but it appears to me that GCC should better print "CDCD", so as to follow
the intent. 

Originated from
http://stackoverflow.com/questions/6315670/when-an-array-is-created-by-a-subexpression-what-happens-with-the-temporaries-th
.



More information about the Gcc-bugs mailing list