Patchwork [v3] Add constexpr specifiers to std::shared_ptr, std::unique_ptr, etc

login
register
mail settings
Submitter Jonathan Wakely
Date Nov. 10, 2010, 10:10 a.m.
Message ID <AANLkTikb6hx3SnQfgD_2s5igmpxVwNNXBLZ0=h1hEmK7@mail.gmail.com>
Download mbox | patch
Permalink /patch/70618/
State New
Headers show

Comments

Jonathan Wakely - Nov. 10, 2010, 10:10 a.m.
On 9 November 2010 10:22, Paolo Carlini wrote:
>
> PS: Jason fixed 46382!

Hoorah! that means we can remove these xfails.
Tested x86_64-linux.

I've also checked in the ChangeLog entry for r166460 which I sent to
the lists but didn't commit.

2010-11-10  Jonathan Wakely  <jwakely.gcc@gmail.com>

        * include/bits/unique_ptr.h: Use static_assert in constexpr
        constructors.
        * testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc: Remove xfails.
        * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust dg-error
        line number.
Paolo Carlini - Nov. 10, 2010, 10:33 a.m.
On 11/10/2010 11:10 AM, Jonathan Wakely wrote:
> On 9 November 2010 10:22, Paolo Carlini wrote:
>   
>> PS: Jason fixed 46382!
>>     
> Hoorah! that means we can remove these xfails.
>   
Great, indeed. Thanks a lot also for your help with the debug-mode
concurrency issues..

Paolo.

Patch

Index: include/bits/unique_ptr.h
===================================================================
--- include/bits/unique_ptr.h	(revision 166515)
+++ include/bits/unique_ptr.h	(working copy)
@@ -109,7 +109,8 @@  _GLIBCXX_BEGIN_NAMESPACE(std)
       // Constructors.
       constexpr unique_ptr()
       : _M_t()
-      { }
+      { static_assert(!std::is_pointer<deleter_type>::value,
+		     "constructed with null function pointer deleter"); }
 
       explicit
       unique_ptr(pointer __p)
@@ -130,7 +131,8 @@  _GLIBCXX_BEGIN_NAMESPACE(std)
 
       constexpr unique_ptr(nullptr_t)
       : _M_t()
-      { }
+      { static_assert(!std::is_pointer<deleter_type>::value,
+		     "constructed with null function pointer deleter"); }
 
       // Move constructors.
       unique_ptr(unique_ptr&& __u)
@@ -269,7 +271,8 @@  _GLIBCXX_BEGIN_NAMESPACE(std)
       // Constructors.
       constexpr unique_ptr()
       : _M_t()
-      { }
+      { static_assert(!std::is_pointer<deleter_type>::value,
+		     "constructed with null function pointer deleter"); }
 
       explicit
       unique_ptr(pointer __p)
@@ -288,10 +291,10 @@  _GLIBCXX_BEGIN_NAMESPACE(std)
       { static_assert(!std::is_reference<deleter_type>::value,
 		      "rvalue deleter bound to reference"); }
 
-      /* TODO: use delegating constructor */
       constexpr unique_ptr(nullptr_t)
       : _M_t()
-      { }
+      { static_assert(!std::is_pointer<deleter_type>::value,
+		     "constructed with null function pointer deleter"); }
 
       // Move constructors.
       unique_ptr(unique_ptr&& __u)
Index: testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc
===================================================================
--- testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc	(revision 166515)
+++ testsuite/20_util/unique_ptr/cons/ptr_deleter_neg.cc	(working copy)
@@ -30,9 +30,9 @@  using std::unique_ptr;
 void
 test01()
 {
-  unique_ptr<int, void(*)(int*)> p1; // { dg-error "here" "" { xfail *-*-* } }
+  unique_ptr<int, void(*)(int*)> p1; // { dg-error "here" }
 
-  unique_ptr<int, void(*)(int*)> p2(nullptr); // { dg-error "here" "" { xfail *-*-* } }
+  unique_ptr<int, void(*)(int*)> p2(nullptr); // { dg-error "here" }
 
   unique_ptr<int, void(*)(int*)> p3(new int); // { dg-error "here" }
 }
@@ -40,9 +40,9 @@  test01()
 void
 test02()
 {
-  unique_ptr<int[], void(*)(int*)> p1; // { dg-error "here" "" { xfail *-*-* } }
+  unique_ptr<int[], void(*)(int*)> p1; // { dg-error "here" }
 
-  unique_ptr<int[], void(*)(int*)> p2(nullptr); // { dg-error "here" "" { xfail *-*-* } }
+  unique_ptr<int[], void(*)(int*)> p2(nullptr); // { dg-error "here" }
 
   unique_ptr<int[], void(*)(int*)> p3(new int[1]); // { dg-error "here" }
 }
Index: testsuite/20_util/weak_ptr/comparison/cmp_neg.cc
===================================================================
--- testsuite/20_util/weak_ptr/comparison/cmp_neg.cc	(revision 166515)
+++ testsuite/20_util/weak_ptr/comparison/cmp_neg.cc	(working copy)
@@ -43,7 +43,7 @@  main()
 
 // { dg-warning "note" "" { target *-*-* } 350 }
 // { dg-warning "note" "" { target *-*-* } 1082 }
-// { dg-warning "note" "" { target *-*-* } 462 }
+// { dg-warning "note" "" { target *-*-* } 465 }
 // { dg-warning "note" "" { target *-*-* } 580 }
 // { dg-warning "note" "" { target *-*-* } 1027 }
 // { dg-warning "note" "" { target *-*-* } 340 }