libstdc++: Adjust static assertions in futures and promises [LWG 3466]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 25 Aug 2020 14:52:57 +0000 (15:52 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 25 Aug 2020 14:52:57 +0000 (15:52 +0100)
Add a static_assertions to check the result type is destructible, as in
the proposed resolution for LWG 3466 (which supersedes 3458).

libstdc++-v3/ChangeLog:

* include/std/future (future, shared_future. promise): Add
is_destructible assertion (LWG 3466). Adjust string-literal for
!is_array and !is_function assertions.
* testsuite/30_threads/future/requirements/lwg3458.cc: Check
types with no accessible destructor. Adjust expected errors.
* testsuite/30_threads/promise/requirements/lwg3466.cc:
Likewise.
* testsuite/30_threads/shared_future/requirements/lwg3458.cc:
Likewise.

libstdc++-v3/include/std/future
libstdc++-v3/testsuite/30_threads/future/requirements/lwg3458.cc
libstdc++-v3/testsuite/30_threads/promise/requirements/lwg3466.cc
libstdc++-v3/testsuite/30_threads/shared_future/requirements/lwg3458.cc

index e0816c2..a7466a3 100644 (file)
@@ -757,8 +757,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 3458. Is shared_future intended to work with arrays or function types?
-      static_assert(!is_array<_Res>{}, "result type is not an array");
-      static_assert(!is_function<_Res>{}, "result type is not a function");
+      static_assert(!is_array<_Res>{}, "result type must not be an array");
+      static_assert(!is_function<_Res>{}, "result type must not be a function");
+      static_assert(is_destructible<_Res>{},
+                   "result type must be destructible");
 
       friend class promise<_Res>;
       template<typename> friend class packaged_task;
@@ -892,8 +894,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 3458. Is shared_future intended to work with arrays or function types?
-      static_assert(!is_array<_Res>{}, "result type is not an array");
-      static_assert(!is_function<_Res>{}, "result type is not a function");
+      static_assert(!is_array<_Res>{}, "result type must not be an array");
+      static_assert(!is_function<_Res>{}, "result type must not be a function");
+      static_assert(is_destructible<_Res>{},
+                   "result type must be destructible");
 
       typedef __basic_future<_Res> _Base_type;
 
@@ -1049,8 +1053,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       // _GLIBCXX_RESOLVE_LIB_DEFECTS
       // 3466: Specify the requirements for promise/future/[...] consistently
-      static_assert(!is_array<_Res>{}, "result type is not an array");
-      static_assert(!is_function<_Res>{}, "result type is not a function");
+      static_assert(!is_array<_Res>{}, "result type must not be an array");
+      static_assert(!is_function<_Res>{}, "result type must not be a function");
+      static_assert(is_destructible<_Res>{},
+                   "result type must be destructible");
 
       typedef __future_base::_State_base       _State;
       typedef __future_base::_Result<_Res>     _Res_type;
index 2bc206c..f26e17b 100644 (file)
@@ -26,9 +26,18 @@ std::future<int(&)[1]> good;
 std::future<int(&)()> good2;
 
 std::future<int[1]> bad; // { dg-error "here" }
-// { dg-error "result type is not an array" "" { target *-*-* } 0 }
+// { dg-error "result type must not be an array" "" { target *-*-* } 0 }
 // { dg-prune-output "function returning an array" }
 
 std::future<int()> bad2; // { dg-error "here" }
-// { dg-error "result type is not a function" "" { target *-*-* } 0 }
+// { dg-error "result type must not be a function" "" { target *-*-* } 0 }
 // { dg-prune-output "function returning a function" }
+
+struct Indestructible { ~Indestructible() = delete; };
+std::future<Indestructible> bad3; // { dg-error "here" }
+// { dg-error "result type must be destructible" "" { target *-*-* } 0 }
+// { dg-prune-output {deleted function} }
+
+class PrivateDtor { public: PrivateDtor(); private: ~PrivateDtor(); };
+std::future<PrivateDtor> bad4; // { dg-error "here" }
+// { dg-prune-output {is private} }
index 124c86c..71eb260 100644 (file)
@@ -26,9 +26,18 @@ std::promise<int(&)[1]> good;
 std::promise<int(&)()> good2;
 
 std::promise<int[1]> bad; // { dg-error "here" }
-// { dg-error "result type is not an array" "" { target *-*-* } 0 }
+// { dg-error "result type must not be an array" "" { target *-*-* } 0 }
 // { dg-prune-output {request for member '~int \[1\]'} }
 
 std::promise<int()> bad2; // { dg-error "here" }
-// { dg-error "result type is not a function" "" { target *-*-* } 0 }
+// { dg-error "result type must not be a function" "" { target *-*-* } 0 }
 // { dg-prune-output {'sizeof \(int\(\)\)'} }
+
+struct Indestructible { ~Indestructible() = delete; };
+std::promise<Indestructible> bad3; // { dg-error "here" }
+// { dg-error "result type must be destructible" "" { target *-*-* } 0 }
+// { dg-prune-output {deleted function} }
+
+class PrivateDtor { public: PrivateDtor(); private: ~PrivateDtor(); };
+std::promise<PrivateDtor> bad4; // { dg-error "here" }
+// { dg-prune-output {is private} }
index df5bfd2..cf76769 100644 (file)
@@ -26,7 +26,16 @@ std::shared_future<int(&)[1]> good;
 std::shared_future<int(&)()> good2;
 
 std::shared_future<int[1]> bad; // { dg-error "here" }
-// { dg-error "result type is not an array" "" { target *-*-* } 0 }
+// { dg-error "result type must not be an array" "" { target *-*-* } 0 }
 
 std::shared_future<int()> bad2; // { dg-error "here" }
-// { dg-error "result type is not a function" "" { target *-*-* } 0 }
+// { dg-error "result type must not be a function" "" { target *-*-* } 0 }
+
+struct Indestructible { ~Indestructible() = delete; };
+std::shared_future<Indestructible> bad3; // { dg-error "here" }
+// { dg-error "result type must be destructible" "" { target *-*-* } 0 }
+// { dg-prune-output {deleted function} }
+
+class PrivateDtor { public: PrivateDtor(); private: ~PrivateDtor(); };
+std::shared_future<PrivateDtor> bad4; // { dg-error "here" }
+// { dg-prune-output {is private} }