Bug 91308 - [7 Regression] unique_ptr assignment fails with different deleters
Summary: [7 Regression] unique_ptr assignment fails with different deleters
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 10.0
: P3 minor
Target Milestone: 7.5
Assignee: Jonathan Wakely
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2019-07-31 12:48 UTC by Jonathan Wakely
Modified: 2019-09-03 12:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 5.5.0
Known to fail: 10.0, 6.4.0, 7.4.0, 8.3.0, 9.1.0
Last reconfirmed: 2019-07-31 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2019-07-31 12:48:32 UTC
As reported at https://gcc.gnu.org/ml/libstdc++/2019-07/msg00088.html this fails to compile:

#include <memory>

struct D1
{
  void operator()(int* p) const noexcept { }
};

struct D2 : D1
{
  D2& operator=(D1&&) noexcept { return *this; }
};

void
test01()
{
  std::unique_ptr<int, D1> d1;
  std::unique_ptr<int, D2> d2;
  d2 = std::move(d1);
}

void
test02()
{
  std::unique_ptr<int[], D1> d1;
  std::unique_ptr<int[], D2> d2;
  d2 = std::move(d1);
}

The constraints on the converting assignment operators incorrectly include this constraint from the converting constructor:

— either D is a reference type and E is the same type as D, or D is not a
  reference type and E is implicitly convertible to D.

This used to compile with GCC 5, until r226733.
Comment 1 Jonathan Wakely 2019-07-31 14:38:57 UTC
Author: redi
Date: Wed Jul 31 14:38:26 2019
New Revision: 273937

URL: https://gcc.gnu.org/viewcvs?rev=273937&root=gcc&view=rev
Log:
PR libstdc++/91308 fix constraints on unique_ptr assignment

	PR libstdc++/91308
	* include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove
	constraints on deleter that should only apply to the constructor.
	(unique_ptr<T[], D>::__safe_conversion_up): Likewise.
	(unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
	constraints on deleter here.
	* testsuite/20_util/unique_ptr/assign/91308.cc: New test.

Added:
    trunk/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/unique_ptr.h
Comment 2 Jonathan Wakely 2019-07-31 19:56:40 UTC
Author: redi
Date: Wed Jul 31 19:56:08 2019
New Revision: 273947

URL: https://gcc.gnu.org/viewcvs?rev=273947&root=gcc&view=rev
Log:
PR libstdc++/91308 fix constraints on unique_ptr assignment

Backport from mainline
2019-07-31  Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/91308
	* include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove
	constraints on deleter that should only apply to the constructor.
	(unique_ptr<T[], D>::__safe_conversion_up): Likewise.
	(unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
	constraints on deleter here.
	* testsuite/20_util/unique_ptr/assign/91308.cc: New test.

Added:
    branches/gcc-9-branch/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc
Modified:
    branches/gcc-9-branch/libstdc++-v3/ChangeLog
    branches/gcc-9-branch/libstdc++-v3/include/bits/unique_ptr.h
Comment 3 Jonathan Wakely 2019-08-30 15:01:46 UTC
Author: redi
Date: Fri Aug 30 15:01:15 2019
New Revision: 275193

URL: https://gcc.gnu.org/viewcvs?rev=275193&root=gcc&view=rev
Log:
PR libstdc++/91308 fix constraints on unique_ptr assignment

Backport from mainline
2019-07-31  Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/91308
	* include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove
	constraints on deleter that should only apply to the constructor.
	(unique_ptr<T[], D>::__safe_conversion_up): Likewise.
	(unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
	constraints on deleter here.
	* testsuite/20_util/unique_ptr/assign/91308.cc: New test.

Added:
    branches/gcc-8-branch/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc
Modified:
    branches/gcc-8-branch/libstdc++-v3/ChangeLog
    branches/gcc-8-branch/libstdc++-v3/include/bits/unique_ptr.h
Comment 4 Jonathan Wakely 2019-09-02 11:10:41 UTC
Author: redi
Date: Mon Sep  2 11:10:04 2019
New Revision: 275311

URL: https://gcc.gnu.org/viewcvs?rev=275311&root=gcc&view=rev
Log:
PR libstdc++/91308 fix constraints on unique_ptr assignment

	* testsuite/20_util/unique_ptr/assign/48635_neg.cc: Replace dg-error
	with dg-prune-output for enable_if failure.
	* testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: Add
	dg-prune-output for enable_if failure.

Backport from mainline
2019-07-31  Jonathan Wakely  <jwakely@redhat.com>

	PR libstdc++/91308
	* include/bits/unique_ptr.h (unique_ptr::__safe_conversion_up): Remove
	constraints on deleter that should only apply to the constructor.
	(unique_ptr<T[], D>::__safe_conversion_up): Likewise.
	(unique_ptr<T[], D>::unique_ptr(unique_ptr<U, D>&&)): Restore
	constraints on deleter here.
	* testsuite/20_util/unique_ptr/assign/91308.cc: New test.

Added:
    branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/unique_ptr/assign/91308.cc
Modified:
    branches/gcc-7-branch/libstdc++-v3/ChangeLog
    branches/gcc-7-branch/libstdc++-v3/include/bits/unique_ptr.h
    branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
    branches/gcc-7-branch/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc
Comment 5 Jonathan Wakely 2019-09-02 11:16:32 UTC
Fixed for 7.5, 8.4 and 9.2
Comment 6 Christophe Lyon 2019-09-03 12:44:05 UTC
On gcc-8-branch, r275193 is causing

FAIL: 20_util/unique_ptr/assign/48635_neg.cc  (test for errors, line 307)
FAIL: 20_util/unique_ptr/assign/48635_neg.cc  (test for errors, line 566)
FAIL: 20_util/unique_ptr/assign/48635_neg.cc (test for excess errors)
FAIL: 20_util/unique_ptr/cons/cv_qual_neg.cc  (test for errors, line 473)
FAIL: 20_util/unique_ptr/cons/cv_qual_neg.cc (test for excess errors)
Comment 7 Jonathan Wakely 2019-09-03 12:52:43 UTC
Fixed at r275296