Re: [PATCH] libstdc++: Reject user-defined specializations for coroutine_handle.
Jonathan Wakely <[email protected]>
| Newsgroups | gmane.comp.gcc.patches,gmane.comp.gcc.libstdc++.devel |
|---|---|
| Message-ID | <CACb0b4=Q0Rku-WUvLR4DZw0eg30JJJ5tutjaDWL0nRwv-O8k7g@mail.gmail.com> |
On Fri, 31 Jul 2026 at 16:01, Tomasz Kamiński <[email protected]> wrote: > > 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. > --- > Disabled warnings in whole file, piggy-backing on existing diagnostic push/pop, > as this file does not define anything else except coroutine_handle, their > specializations for void and __noop_promise, and hash. > > Testing on x86_64-linux. *coroutine* test passed with all standard > modes, and debug. OK for trunk when all test passes. OK > > *simd* is bit larger in scope, as the wording applies to all template > defined in this header, including the helpers. > > > libstdc++-v3/include/std/coroutine | 3 ++- > .../coroutines/specializations_neg.cc | 18 ++++++++++++++++++ > 2 files changed, 20 insertions(+), 1 deletion(-) > create mode 100644 libstdc++-v3/testsuite/18_support/coroutines/specializations_neg.cc > > diff --git a/libstdc++-v3/include/std/coroutine b/libstdc++-v3/include/std/coroutine > index 7f7295d0fa5..61ca185a1a4 100644 > --- a/libstdc++-v3/include/std/coroutine > +++ b/libstdc++-v3/include/std/coroutine > @@ -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 > index 00000000000..0e7aabc6b0b > --- /dev/null > +++ b/libstdc++-v3/testsuite/18_support/coroutines/specializations_neg.cc > @@ -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" } > +{}; > -- > 2.55.0 >