http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60372
Bug ID: 60372
Summary: incorrect destruction order for function parameter
objects
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jens.maurer at gmx dot net
Parameter objects are not destroyed when the called function returns, but later
(too late). The C++ standard says in 5.2.2p4 [expr.call]:
"... The lifetime of a parameter ends when the function in which it is defined
returns. ..."
However, the following program shows that "S" is destroyed too late, after the
call to h():
#include <stdio.h>
struct S {
S(int) { printf("S(int)\n"); }
~S() { printf("~S\n"); }
};
void f(S) { printf("f(S)\n"); }
void h() { printf("h()\n"); }
int main()
{
f({0}), h();
}
> g++ -Wall -Wextra -std=c++11 -pedantic func-destroy.cc
> ./a.out
S(int)
f(S)
h()
~S
"S" should be destroyed before the call to h(). Note that no temporary is
involved (which would correctly be destroyed at the end of the
full-expression); the copy-list-initialization initializes the parameter
object.