Bug 79679 - [7 Regression] [C++17] Missing destruction of temporary within constructor's mem-initializer-list
Summary: [7 Regression] [C++17] Missing destruction of temporary within constructor's ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.0.1
: P3 normal
Target Milestone: 7.0
Assignee: Jason Merrill
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2017-02-22 17:45 UTC by Stephan Bergmann
Modified: 2017-02-23 01:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 6.3.0
Known to fail: 7.0.1
Last reconfirmed: 2017-02-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephan Bergmann 2017-02-22 17:45:43 UTC
At least with a recent GCC trunk build ("gcc (GCC) 7.0.1 20170221 (experimental)"), the below program does not print "dtor" when built with -std=c++17 (but does when built with -std=c++14, or with an older GCC, gcc-c++-6.3.1-1.fc25.x86_64).  Appears that in the U ctor, a temporary shared_ptr<S> is copy-created but not destroyed.


#include <iostream>
#include <memory>
struct S { ~S() { std::cout << "dtor\n"; } };
struct T {
    std::shared_ptr<S> s_;
    T(std::shared_ptr<S> s): s_(s) {}
};
struct U {
    T t_;
    U(std::shared_ptr<S> const & s): t_(s) {}
};
int main() {
    auto s = std::make_shared<S>();
    U u(s);
}
Comment 1 Jonathan Wakely 2017-02-22 22:38:29 UTC
int count;
struct S {
    S() { ++count; }
    S(const S&) { ++count; }
    ~S() { --count; }
};

struct T {
    T(S) {}
};

int main() {
  {
    S s;
    T u(s);
  }
  if (count)
    __builtin_abort();
}
Comment 2 Jonathan Wakely 2017-02-22 23:00:11 UTC
Started with r245612

        PR c++/78139 - destructor needed by new-expression
    
        * call.c (build_special_member_call): Use tf_no_cleanup.
Comment 3 Jason Merrill 2017-02-23 01:16:06 UTC
Fixed.
Comment 4 Jason Merrill 2017-02-23 01:16:16 UTC
Author: jason
Date: Thu Feb 23 01:15:43 2017
New Revision: 245672

URL: https://gcc.gnu.org/viewcvs?rev=245672&root=gcc&view=rev
Log:
	PR c++/79679 - missing destructor for argument
	* call.c (build_over_call): Don't pass tf_no_cleanup to argument
	conversions.

Added:
    trunk/gcc/testsuite/g++.dg/init/cleanup4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c