This is the mail archive of the libstdc++-cvs@gcc.gnu.org mailing list for the libstdc++ 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]

r194874 - in /branches/google/gcc-4_7/libstdc++...


Author: crowl
Date: Fri Jan  4 00:05:12 2013
New Revision: 194874

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=194874
Log:
Relax the restrictions on argument types to a unique_ptr
instantiated on an array type.  This patch is a backport
of Jonathan Wakely's "std::unique_ptr<T[], D> improvements"
http://gcc.gnu.org/ml/gcc-patches/2012-12/msg01271.html to the
google 4.7 branch.

The existing unique_ptr admits no conversions, not even
cv-qualification conversions.  The patch permits cv-qualification
conversion.  It prohibits derived-to-base pointer conversion, as
is needed to prevent improper deletion.  It permits user-defined
pointer types.  The latter permissiveness is under debate.  Given

  struct base { };
  struct derived : base { };

as we cannot presently distinguish between the safe

  struct ptr_base {
    operator base*() { return 0; }
  };

  ... unique_ptr< base >( ptr_base() );

and the unsafe

  struct ptr_derived {
    operator derived*() { return 0; }
  };

  ... unique_ptr< base >( ptr_derived() );

No existing code can encounter the unsafe part because no existing
code can have user-defined pointer types.  There are likely to be
very few uses of user-defined pointers introduced into the code
base between now and when the issue is resolved.  So, backporting
the patch as is seems safe enough, and not too much trouble to
correct later.

Tested on x86_64.  Tests pass through Google's core and mantle,
but fail for apparently unrelated reasons in crust.



Modified:
    branches/google/gcc-4_7/libstdc++-v3/include/bits/shared_ptr_base.h
    branches/google/gcc-4_7/libstdc++-v3/include/bits/unique_ptr.h
    branches/google/gcc-4_7/libstdc++-v3/include/std/type_traits
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/shared_ptr/cons/unique_ptr.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/unique_ptr/cons/pointer_array_convertible_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/unique_ptr/modifiers/reset_neg.cc
    branches/google/gcc-4_7/libstdc++-v3/testsuite/20_util/unique_ptr/requirements/pointer_type.cc


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