re PR libstdc++/43820 (auto_ptr used with incomplete type no longer triggers warning)
authorJonathan Wakely <jwakely.gcc@gmail.com>
Mon, 31 May 2010 18:41:33 +0000 (18:41 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 31 May 2010 18:41:33 +0000 (18:41 +0000)
2010-05-31  Jonathan Wakely  <jwakely.gcc@gmail.com>

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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/include/tr1/shared_ptr.h
libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820.cc [new file with mode: 0644]
libstdc++-v3/testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc [new file with mode: 0644]

index 4932edd..13d7ea8 100644 (file)
@@ -1,3 +1,11 @@
+2010-05-31  Jonathan Wakely  <jwakely.gcc@gmail.com>
+
+       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  <paolo.carlini@oracle.com>
 
        * include/bits/basic_string.h (front, back): Add.
index 1999f36..0c366b8 100644 (file)
@@ -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 6176b5e..f504e08 100644 (file)
@@ -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);
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 (file)
index 0000000..6350079
--- /dev/null
@@ -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 "" }
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 (file)
index 0000000..b5fe356
--- /dev/null
@@ -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 "" }