[v3] PR43820 require complete type in shared_ptr
Jonathan Wakely
jwakely.gcc@gmail.com
Thu May 27 12:46:00 GMT 2010
PR libstdc++/43820
* include/bits/shared_ptr_base.h: Require complete type.
* include/tr1/shared_ptr.h: Likewise.
* testsuite/20_util/shared_ptr/cons/43820.cc: New.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc: New.
This addresses the shared_ptr part of PR43820.
Tested x86_64/Linux. I'm away for a few days, will commit to trunk
when I get back. Although it's a regression this change makes invalid
uses into a hard error where we only warned in old releases, so I'm
not sure about applying it to 4.4 and 4.5
-------------- next part --------------
Index: include/bits/shared_ptr_base.h
===================================================================
--- include/bits/shared_ptr_base.h (revision 159913)
+++ include/bits/shared_ptr_base.h (working copy)
@@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{ delete this; }
virtual void*
- _M_get_deleter(const std::type_info& __ti)
+ _M_get_deleter(const std::type_info&)
{ return 0; }
_Sp_counted_ptr(const _Sp_counted_ptr&) = delete;
@@ -545,7 +545,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
explicit __shared_ptr(_Tp1* __p) : _M_ptr(__p), _M_refcount(__p)
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // __glibcxx_function_requires(_CompleteConcept<_Tp1*>)
+ static_assert( sizeof(_Tp1) > 0, "incomplete type" );
__enable_shared_from_this_helper(_M_refcount, __p, __p);
}
@@ -624,7 +624,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _M_ptr(__r.get()), _M_refcount()
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // TODO requires _Tp1 is complete, delete __r.release() well-formed
+ static_assert( sizeof(_Tp1) > 0, "incomplete type" );
_Tp1* __tmp = __r.get();
_M_refcount = __shared_count<_Lp>(std::move(__r));
__enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
Index: include/tr1/shared_ptr.h
===================================================================
--- include/tr1/shared_ptr.h (revision 159913)
+++ include/tr1/shared_ptr.h (working copy)
@@ -1,6 +1,6 @@
// <tr1/shared_ptr.h> -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -367,7 +367,7 @@ namespace tr1
: _M_ptr(__p), _M_refcount(__p)
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // __glibcxx_function_requires(_CompleteConcept<_Tp1*>)
+ typedef int _IsComplete[sizeof(_Tp1)];
__enable_shared_from_this_helper(_M_refcount, __p, __p);
}
@@ -404,9 +404,9 @@ namespace tr1
explicit
__shared_ptr(std::auto_ptr<_Tp1>& __r)
: _M_ptr(__r.get()), _M_refcount()
- {
+ { // TODO requries delete __r.release() well-formed
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // TODO requires _Tp1 is complete, delete __r.release() well-formed
+ typedef int _IsComplete[sizeof(_Tp1)];
_Tp1* __tmp = __r.get();
_M_refcount = __shared_count<_Lp>(__r);
__enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
Index: testsuite/20_util/shared_ptr/cons/43820.cc
===================================================================
--- testsuite/20_util/shared_ptr/cons/43820.cc (revision 0)
+++ testsuite/20_util/shared_ptr/cons/43820.cc (revision 0)
@@ -0,0 +1,42 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 20.9.11.2 Template class shared_ptr [util.smartptr.shared]
+
+#include <memory>
+
+// incomplete type
+struct X;
+
+// get an auto_ptr rvalue
+std::auto_ptr<X>&& ap();
+
+void test01()
+{
+ X* px = 0;
+ std::shared_ptr<X> p1(px); // { dg-error "here" }
+ // { dg-error "incomplete" "" { target *-*-* } 549 }
+
+ std::shared_ptr<X> p9(ap()); // { dg-error "here" }
+ // { dg-error "incomplete" "" { target *-*-* } 630 }
+
+}
+
+// { dg-excess-errors "" }
Index: testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc
===================================================================
--- testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc (revision 0)
+++ testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc (revision 0)
@@ -0,0 +1,40 @@
+// { dg-do compile }
+
+// Copyright (C) 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 2.2.3 Class template shared_ptr [tr.util.smartptr.shared]
+
+#include <tr1/memory>
+
+// incomplete type
+struct X;
+
+std::auto_ptr<X>& ap();
+
+void test01()
+{
+ X* px = 0;
+ std::tr1::shared_ptr<X> p1(px); // { dg-error "here" }
+ // { dg-error "incomplete" "" { target *-*-* } 370 }
+
+ std::tr1::shared_ptr<X> p9(ap()); // { dg-error "here" }
+ // { dg-error "incomplete" "" { target *-*-* } 409 }
+
+}
+
+// { dg-excess-errors "" }
More information about the Libstdc++
mailing list