From: Jonathan Wakely Date: Mon, 31 May 2010 18:41:33 +0000 (+0000) Subject: re PR libstdc++/43820 (auto_ptr used with incomplete type no longer triggers warning) X-Git-Tag: upstream/12.2.0~92730 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4585cf723650a3e5632649a52b354041c57e860d;p=platform%2Fupstream%2Fgcc.git re PR libstdc++/43820 (auto_ptr used with incomplete type no longer triggers warning) 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. From-SVN: r160082 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4932edd..13d7ea8 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 1999f36..0c366b8 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 6176b5e..f504e08 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 0000000..6350079 --- /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 0000000..b5fe356 --- /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 "" }