From c367c0a74dee0a32ab06f7342f3a1779300af767 Mon Sep 17 00:00:00 2001 From: paolo Date: Mon, 31 May 2010 18:41:33 +0000 Subject: [PATCH] 2010-05-31 Jonathan Wakely 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160082 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 8 ++++ libstdc++-v3/include/bits/shared_ptr_base.h | 6 +-- libstdc++-v3/include/tr1/shared_ptr.h | 8 ++-- .../20_util/shared_ptr/cons/43820.cc | 42 +++++++++++++++++++ .../shared_ptr/cons/43820.cc | 40 ++++++++++++++++++ 5 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc create mode 100644 libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4932edd52c89..13d7ea82ba03 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2010-05-31 Jonathan Wakely + + 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. + 2010-05-31 Paolo Carlini * include/bits/basic_string.h (front, back): Add. diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index 1999f36023bb..0c366b8ef1a5 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -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); diff --git a/libstdc++-v3/include/tr1/shared_ptr.h b/libstdc++-v3/include/tr1/shared_ptr.h index 6176b5e48140..f504e083c52f 100644 --- a/libstdc++-v3/include/tr1/shared_ptr.h +++ b/libstdc++-v3/include/tr1/shared_ptr.h @@ -1,6 +1,6 @@ // -*- 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); diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc new file mode 100644 index 000000000000..635007998384 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc @@ -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 +// . + +// 20.9.11.2 Template class shared_ptr [util.smartptr.shared] + +#include + +// incomplete type +struct X; + +// get an auto_ptr rvalue +std::auto_ptr&& ap(); + +void test01() +{ + X* px = 0; + std::shared_ptr p1(px); // { dg-error "here" } + // { dg-error "incomplete" "" { target *-*-* } 549 } + + std::shared_ptr p9(ap()); // { dg-error "here" } + // { dg-error "incomplete" "" { target *-*-* } 630 } + +} + +// { dg-excess-errors "" } diff --git a/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc b/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc new file mode 100644 index 000000000000..b5fe3567f9ad --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc @@ -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 +// . + +// 2.2.3 Class template shared_ptr [tr.util.smartptr.shared] + +#include + +// incomplete type +struct X; + +std::auto_ptr& ap(); + +void test01() +{ + X* px = 0; + std::tr1::shared_ptr p1(px); // { dg-error "here" } + // { dg-error "incomplete" "" { target *-*-* } 370 } + + std::tr1::shared_ptr p9(ap()); // { dg-error "here" } + // { dg-error "incomplete" "" { target *-*-* } 409 } + +} + +// { dg-excess-errors "" } -- 2.47.2