]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Reject user-defined specializations for coroutine_handle.
authorTomasz Kamiński <tkaminsk@redhat.com>
Fri, 31 Jul 2026 14:52:09 +0000 (16:52 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Fri, 31 Jul 2026 15:00:46 +0000 (17:00 +0200)
The P0912R5, "Merge Coroutines TS into C++20 working draft" that
introduced them already included made specializing coroutine_handle
ill-formed, no diagnostic required.

This is QoI improvment, that produces diagnostic in such situation
by decaroting base template with [[_Clang::__no_specializations]].

libstdc++-v3/ChangeLog:

* include/std/coroutine: Ignore -Winvalid-specialization in file.
(std::coroutine_handle): Add clang::no_specializations attribute.
* testsuite/18_support/coroutines/specializations_neg.cc: New test.

libstdc++-v3/include/std/coroutine
libstdc++-v3/testsuite/18_support/coroutines/specializations_neg.cc [new file with mode: 0644]

index 7f7295d0fa57c896c9b79b71e355043de511d787..61ca185a1a47f2d461ae1882408b17dc917384e4 100644 (file)
@@ -35,6 +35,7 @@
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wc++17-extensions"
+#pragma GCC diagnostic ignored "-Winvalid-specialization"
 
 #define __glibcxx_want_coroutine
 #include <bits/version.h>
@@ -195,7 +196,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template <typename _Promise>
-    struct coroutine_handle
+    struct _GLIBCXX_NO_SPECIALIZATIONS coroutine_handle
     {
       // [coroutine.handle.con], construct/reset
 
diff --git a/libstdc++-v3/testsuite/18_support/coroutines/specializations_neg.cc b/libstdc++-v3/testsuite/18_support/coroutines/specializations_neg.cc
new file mode 100644 (file)
index 0000000..0e7aabc
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++20 } }
+
+#include <coroutine>
+
+struct Promise
+{};
+
+template<>
+struct std::coroutine_handle<Promise> // { dg-error "cannot be specialized" }
+{};
+
+template<typename>
+struct PromiseTempl
+{};
+
+template<typename T>
+struct std::coroutine_handle<PromiseTempl<T>> // { dg-error "cannot be specialized" }
+{};