[committed] libstdc++: std::make_signed_t<cv bool> should be ill-formed
Commit Message
Tested powerpc64le-linux. Pushed to trunk.
-- >8 --
Currently we only reject std::make_signed_t<bool> but not cv bool.
Similarly for std::make_unsigned_t<cv bool>.
As well as making those ill-formed, this adds a requires-clause to the
make_signed and make_unsigned primary templates. This makes
non-integral, non-enum cases fail immediately with a clear error, rather
than giving an error about __make_signed_selector<T, false, false> being
incomplete.
libstdc++-v3/ChangeLog:
* include/std/type_traits (make_signed, make_unsigned): Add
specializations for cv bool. Add requires-clause for C++20 to
improve diagnostics for non-integral, non-enum cases.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Check cv bool.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Adjust expected errors for C++20 and later.
* testsuite/lib/prune.exp: Prune "in requirements [with ...]"
lines from diagnostics.
---
libstdc++-v3/include/std/type_traits | 18 ++++++++++---
.../make_signed/requirements/typedefs_neg.cc | 27 +++++++++----------
.../requirements/typedefs_neg.cc | 25 ++++++++---------
.../range_access/range_access_cpp20_neg.cc | 3 ++-
libstdc++-v3/testsuite/lib/prune.exp | 1 +
5 files changed, 40 insertions(+), 34 deletions(-)
Comments
On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
> Tested powerpc64le-linux. Pushed to trunk.
>
> -- >8 --
>
> Currently we only reject std::make_signed_t<bool> but not cv bool.
> Similarly for std::make_unsigned_t<cv bool>.
>
> As well as making those ill-formed, this adds a requires-clause to the
> make_signed and make_unsigned primary templates. This makes
> non-integral, non-enum cases fail immediately with a clear error, rather
> than giving an error about __make_signed_selector<T, false, false> being
> incomplete.
IIUC the requires-clause turns what was once a hard error into a SFINAE
error, so e.g. for
template<class T> typename make_signed<T>::type f(int);
template<class T> void f(...);
int main() { f<void>(0); }
the call to f would previously be rejected due to an error outside the
immediate context about incomplete __make_signed_selector, and now with
the requires-clause resolves to the second overload. I wonder if this
new behavior is conforming -- the examples in [structure.specifications]
of how to implement 'Mandates' suggest that a failed 'Mandates' should
yield a hard error?
>
> libstdc++-v3/ChangeLog:
>
> * include/std/type_traits (make_signed, make_unsigned): Add
> specializations for cv bool. Add requires-clause for C++20 to
> improve diagnostics for non-integral, non-enum cases.
> * testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
> Check cv bool.
> * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
> Likewise.
> * testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
> Adjust expected errors for C++20 and later.
> * testsuite/lib/prune.exp: Prune "in requirements [with ...]"
> lines from diagnostics.
> ---
> libstdc++-v3/include/std/type_traits | 18 ++++++++++---
> .../make_signed/requirements/typedefs_neg.cc | 27 +++++++++----------
> .../requirements/typedefs_neg.cc | 25 ++++++++---------
> .../range_access/range_access_cpp20_neg.cc | 3 ++-
> libstdc++-v3/testsuite/lib/prune.exp | 1 +
> 5 files changed, 40 insertions(+), 34 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index b74565eb521..6108b98aa6a 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -1802,12 +1802,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> // Primary template.
> /// make_unsigned
> template<typename _Tp>
> +#if __cpp_concepts
> + requires is_integral<_Tp>::value || __is_enum(_Tp)
> +#endif
> struct make_unsigned
> { typedef typename __make_unsigned_selector<_Tp>::__type type; };
>
> // Integral, but don't define.
> - template<>
> - struct make_unsigned<bool>;
> + template<> struct make_unsigned<bool>;
> + template<> struct make_unsigned<bool const>;
> + template<> struct make_unsigned<bool volatile>;
> + template<> struct make_unsigned<bool const volatile>;
>
> /// @cond undocumented
>
> @@ -1932,12 +1937,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> // Primary template.
> /// make_signed
> template<typename _Tp>
> +#if __cpp_concepts
> + requires is_integral<_Tp>::value || __is_enum(_Tp)
> +#endif
> struct make_signed
> { typedef typename __make_signed_selector<_Tp>::__type type; };
>
> // Integral, but don't define.
> - template<>
> - struct make_signed<bool>;
> + template<> struct make_signed<bool>;
> + template<> struct make_signed<bool const>;
> + template<> struct make_signed<bool volatile>;
> + template<> struct make_signed<bool const volatile>;
>
> #if __cplusplus > 201103L
> /// Alias template for make_signed
> diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
> index 051bb64c710..88b8ae887ef 100644
> --- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
> +++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
> @@ -20,31 +20,28 @@
> // <http://www.gnu.org/licenses/>.
>
> #include <type_traits>
> -#include <testsuite_character.h>
>
> -enum test_enum { first_selection };
> +struct pod_class { };
>
> void test01()
> {
> using std::make_signed;
>
> // Negative tests.
> - typedef make_signed<bool>::type test1_type;
> + using T1 = make_signed<bool>::type; // { dg-error "incomplete" }
> + using T2 = make_signed<const bool>::type; // { dg-error "incomplete" }
> + using T3 = make_signed<volatile bool>::type; // { dg-error "incomplete" }
> + using T4 = make_signed<const volatile bool>::type; // { dg-error "incomplete" }
>
> - typedef make_signed<__gnu_test::pod_uint>::type test2_type;
> + using T5 = make_signed<pod_class>::type; // { dg-error "here" }
>
> - typedef make_signed<int[4]>::type test3_type;
> + using T6 = make_signed<int[4]>::type; // { dg-error "here" }
>
> - typedef void (fn_type) ();
> - typedef make_signed<fn_type>::type test4_type;
> + using fn_type = void ();
> + using T7 = make_signed<fn_type>::type; // { dg-error "here" }
>
> - typedef make_signed<float>::type test5_type;
> + using T8 = make_signed<float>::type; // { dg-error "here" }
> }
>
> -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 }
> -// { dg-error "required from here" "" { target *-*-* } 34 }
> -// { dg-error "required from here" "" { target *-*-* } 36 }
> -// { dg-error "required from here" "" { target *-*-* } 39 }
> -// { dg-error "required from here" "" { target *-*-* } 41 }
> -
> -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
> +// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
> +// { dg-error "constraint failure" "" { target c++20 } 0 }
> diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
> index ff98cc42ef7..50f15e7037c 100644
> --- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
> +++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
> @@ -21,7 +21,6 @@
>
> #include <type_traits>
>
> -enum test_enum { first_selection };
> struct pod_class { };
>
> void test01()
> @@ -29,22 +28,20 @@ void test01()
> using std::make_unsigned;
>
> // Negative tests.
> - typedef make_unsigned<bool>::type test1_type;
> + using T1 = make_unsigned<bool>::type; // { dg-error "incomplete" }
> + using T2 = make_unsigned<const bool>::type; // { dg-error "incomplete" }
> + using T3 = make_unsigned<volatile bool>::type; // { dg-error "incomplete" }
> + using T4 = make_unsigned<const volatile bool>::type; // { dg-error "incomplete" }
>
> - typedef make_unsigned<pod_class>::type test2_type;
> + using T5 = make_unsigned<pod_class>::type; // { dg-error "here" }
>
> - typedef make_unsigned<int[4]>::type test3_type;
> + using T6 = make_unsigned<int[4]>::type; // { dg-error "here" }
>
> - typedef void (fn_type) ();
> - typedef make_unsigned<fn_type>::type test4_type;
> + using fn_type = void ();
> + using T7 = make_unsigned<fn_type>::type; // { dg-error "here" }
>
> - typedef make_unsigned<float>::type test5_type;
> + using T8 = make_unsigned<float>::type; // { dg-error "here" }
> }
>
> -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 }
> -// { dg-error "required from here" "" { target *-*-* } 34 }
> -// { dg-error "required from here" "" { target *-*-* } 36 }
> -// { dg-error "required from here" "" { target *-*-* } 39 }
> -// { dg-error "required from here" "" { target *-*-* } 41 }
> -
> -// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
> +// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
> +// { dg-error "constraint failure" "" { target c++20 } 0 }
> diff --git a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc
> index c0825a58587..26c8ae0ee1e 100644
> --- a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc
> +++ b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc
> @@ -46,4 +46,5 @@ test03()
> C c;
> std::ssize(c); // { dg-error "no matching function" }
> }
> -// { dg-error "incomplete type .*make_signed.*S" "" { target *-*-* } 0 }
> +// { dg-error "incomplete type .*make_signed.*S" "" { target c++17_down } 0 }
> +// { dg-error "constraint failure" "" { target c++20 } 0 }
> diff --git a/libstdc++-v3/testsuite/lib/prune.exp b/libstdc++-v3/testsuite/lib/prune.exp
> index d457e975218..6d0b77a8ccd 100644
> --- a/libstdc++-v3/testsuite/lib/prune.exp
> +++ b/libstdc++-v3/testsuite/lib/prune.exp
> @@ -51,6 +51,7 @@ proc libstdc++-dg-prune { system text } {
> regsub -all "(^|\n)\[^\n\]*: (recursively )?required \[^\n\]*" $text "" text
> regsub -all "(^|\n)\[^\n\]*: . skipping \[0-9\]* instantiation contexts \[^\n\]*" $text "" text
> regsub -all "(^|\n)\[^\n\]*: in .constexpr. expansion \[^\n\]*" $text "" text
> + regsub -all "(^|\n)\[^\n\]*: in requirements .with\[^\n\]*" $text "" text
> regsub -all "(^|\n) inlined from \[^\n\]*" $text "" text
> # Why doesn't GCC need these to strip header context?
> regsub -all "(^|\n)In file included from \[^\n\]*" $text "" text
> --
> 2.37.3
>
>
On Mon, Oct 10, 2022 at 8:09 AM Patrick Palka via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
>
> > Tested powerpc64le-linux. Pushed to trunk.
> >
> > -- >8 --
> >
> > Currently we only reject std::make_signed_t<bool> but not cv bool.
> > Similarly for std::make_unsigned_t<cv bool>.
> >
> > As well as making those ill-formed, this adds a requires-clause to the
> > make_signed and make_unsigned primary templates. This makes
> > non-integral, non-enum cases fail immediately with a clear error, rather
> > than giving an error about __make_signed_selector<T, false, false> being
> > incomplete.
>
> IIUC the requires-clause turns what was once a hard error into a SFINAE
> error, so e.g. for
>
> template<class T> typename make_signed<T>::type f(int);
> template<class T> void f(...);
> int main() { f<void>(0); }
>
> the call to f would previously be rejected due to an error outside the
> immediate context about incomplete __make_signed_selector, and now with
> the requires-clause resolves to the second overload. I wonder if this
> new behavior is conforming -- the examples in [structure.specifications]
> of how to implement 'Mandates' suggest that a failed 'Mandates' should
> yield a hard error?
I'm also concerned about the inability to name make_signed<X> in a
context that doesn't require its instantiation (e.g.,
conditional_t<is_integral_v<T>, make_signed<T>,
type_identity<T>>::type). That seems a plausible use case, and
breaking it doesn't seem great to me (conformance aside).
On Mon, 10 Oct 2022 at 14:50, Tim Song via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> On Mon, Oct 10, 2022 at 8:09 AM Patrick Palka via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
> >
> > > Tested powerpc64le-linux. Pushed to trunk.
> > >
> > > -- >8 --
> > >
> > > Currently we only reject std::make_signed_t<bool> but not cv bool.
> > > Similarly for std::make_unsigned_t<cv bool>.
> > >
> > > As well as making those ill-formed, this adds a requires-clause to the
> > > make_signed and make_unsigned primary templates. This makes
> > > non-integral, non-enum cases fail immediately with a clear error, rather
> > > than giving an error about __make_signed_selector<T, false, false> being
> > > incomplete.
> >
> > IIUC the requires-clause turns what was once a hard error into a SFINAE
> > error, so e.g. for
> >
> > template<class T> typename make_signed<T>::type f(int);
> > template<class T> void f(...);
> > int main() { f<void>(0); }
> >
> > the call to f would previously be rejected due to an error outside the
> > immediate context about incomplete __make_signed_selector, and now with
> > the requires-clause resolves to the second overload. I wonder if this
> > new behavior is conforming -- the examples in [structure.specifications]
> > of how to implement 'Mandates' suggest that a failed 'Mandates' should
> > yield a hard error?
>
> I'm also concerned about the inability to name make_signed<X> in a
> context that doesn't require its instantiation (e.g.,
> conditional_t<is_integral_v<T>, make_signed<T>,
> type_identity<T>>::type). That seems a plausible use case, and
> breaking it doesn't seem great to me (conformance aside).
Ah yes, that's a problem.
We could fix it like this:
template<typename _Tp>
struct make_unsigned;
template<typename _Tp>
#if __cpp_concepts
requires is_integral<_Tp>::value || __is_enum(_Tp)
struct make_unsigned<_Tp>
#else
struct make_unsigned
#endif
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };
But that doesn't really improve the diagnostic much. It's simpler
just to revert the addition of the constraints.
On Mon, 10 Oct 2022 at 15:05, Jonathan Wakely wrote:
>
> On Mon, 10 Oct 2022 at 14:50, Tim Song via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
> >
> > On Mon, Oct 10, 2022 at 8:09 AM Patrick Palka via Libstdc++
> > <libstdc++@gcc.gnu.org> wrote:
> > >
> > > On Mon, 10 Oct 2022, Jonathan Wakely via Libstdc++ wrote:
> > >
> > > > Tested powerpc64le-linux. Pushed to trunk.
> > > >
> > > > -- >8 --
> > > >
> > > > Currently we only reject std::make_signed_t<bool> but not cv bool.
> > > > Similarly for std::make_unsigned_t<cv bool>.
> > > >
> > > > As well as making those ill-formed, this adds a requires-clause to the
> > > > make_signed and make_unsigned primary templates. This makes
> > > > non-integral, non-enum cases fail immediately with a clear error, rather
> > > > than giving an error about __make_signed_selector<T, false, false> being
> > > > incomplete.
> > >
> > > IIUC the requires-clause turns what was once a hard error into a SFINAE
> > > error, so e.g. for
> > >
> > > template<class T> typename make_signed<T>::type f(int);
> > > template<class T> void f(...);
> > > int main() { f<void>(0); }
> > >
> > > the call to f would previously be rejected due to an error outside the
> > > immediate context about incomplete __make_signed_selector, and now with
> > > the requires-clause resolves to the second overload. I wonder if this
> > > new behavior is conforming -- the examples in [structure.specifications]
> > > of how to implement 'Mandates' suggest that a failed 'Mandates' should
> > > yield a hard error?
> >
> > I'm also concerned about the inability to name make_signed<X> in a
> > context that doesn't require its instantiation (e.g.,
> > conditional_t<is_integral_v<T>, make_signed<T>,
> > type_identity<T>>::type). That seems a plausible use case, and
> > breaking it doesn't seem great to me (conformance aside).
>
> Ah yes, that's a problem.
>
> We could fix it like this:
>
> template<typename _Tp>
> struct make_unsigned;
>
> template<typename _Tp>
> #if __cpp_concepts
> requires is_integral<_Tp>::value || __is_enum(_Tp)
> struct make_unsigned<_Tp>
> #else
> struct make_unsigned
> #endif
> { typedef typename __make_unsigned_selector<_Tp>::__type type; };
>
> But that doesn't really improve the diagnostic much. It's simpler
> just to revert the addition of the constraints.
Reverted like so. Tested powerpc64le-linux, pushed to trunk.
commit 1d2f07ed4ce028a7c1f9b18f5d959f30213545ca
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Oct 10 15:06:53 2022
libstdc++: Revert addition of constraints to make_signed/make_unsigned
Constraining the primary template makes it unusable in uninstantiated
contexts.
libstdc++-v3/ChangeLog:
* include/std/type_traits (make_signed, make_unsigned): Remove
constraints on primary template.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc:
Undo changes to expected error in C++20 mode.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/24_iterators/range_access/range_access_cpp20_neg.cc:
Likewise.
* testsuite/20_util/make_signed/requirements/uninstantiated.cc:
New test.
* testsuite/20_util/make_unsigned/requirements/uninstantiated.cc:
New test.
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 6108b98aa6a..1d7c3b04a0e 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -1802,9 +1802,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Primary template.
/// make_unsigned
template<typename _Tp>
-#if __cpp_concepts
- requires is_integral<_Tp>::value || __is_enum(_Tp)
-#endif
struct make_unsigned
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };
@@ -1937,9 +1934,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Primary template.
/// make_signed
template<typename _Tp>
-#if __cpp_concepts
- requires is_integral<_Tp>::value || __is_enum(_Tp)
-#endif
struct make_signed
{ typedef typename __make_signed_selector<_Tp>::__type type; };
diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
index 88b8ae887ef..451eeb8c92d 100644
--- a/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/typedefs_neg.cc
@@ -43,5 +43,4 @@ void test01()
using T8 = make_signed<float>::type; // { dg-error "here" }
}
-// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
-// { dg-error "constraint failure" "" { target c++20 } 0 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
diff --git a/libstdc++-v3/testsuite/20_util/make_signed/requirements/uninstantiated.cc b/libstdc++-v3/testsuite/20_util/make_signed/requirements/uninstantiated.cc
new file mode 100644
index 00000000000..3facf0c595a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/make_signed/requirements/uninstantiated.cc
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++11 } }
+#include <type_traits>
+
+// Check that we can name invalid specializations, just don't instantiate them.
+
+using X = std::make_signed<float>;
+using Y = std::make_signed<bool>;
+using Z = std::make_signed<void>;
diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
index 50f15e7037c..49d520936a3 100644
--- a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc
@@ -43,5 +43,4 @@ void test01()
using T8 = make_unsigned<float>::type; // { dg-error "here" }
}
-// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
-// { dg-error "constraint failure" "" { target c++20 } 0 }
+// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
diff --git a/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/uninstantiated.cc b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/uninstantiated.cc
new file mode 100644
index 00000000000..9b860967379
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/make_unsigned/requirements/uninstantiated.cc
@@ -0,0 +1,8 @@
+// { dg-do compile { target c++11 } }
+#include <type_traits>
+
+// Check that we can name invalid specializations, just don't instantiate them.
+
+using X = std::make_unsigned<float>;
+using Y = std::make_unsigned<bool>;
+using Z = std::make_unsigned<void>;
diff --git a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc
index 26c8ae0ee1e..c0825a58587 100644
--- a/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc
+++ b/libstdc++-v3/testsuite/24_iterators/range_access/range_access_cpp20_neg.cc
@@ -46,5 +46,4 @@ test03()
C c;
std::ssize(c); // { dg-error "no matching function" }
}
-// { dg-error "incomplete type .*make_signed.*S" "" { target c++17_down } 0 }
-// { dg-error "constraint failure" "" { target c++20 } 0 }
+// { dg-error "incomplete type .*make_signed.*S" "" { target *-*-* } 0 }
@@ -1802,12 +1802,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Primary template.
/// make_unsigned
template<typename _Tp>
+#if __cpp_concepts
+ requires is_integral<_Tp>::value || __is_enum(_Tp)
+#endif
struct make_unsigned
{ typedef typename __make_unsigned_selector<_Tp>::__type type; };
// Integral, but don't define.
- template<>
- struct make_unsigned<bool>;
+ template<> struct make_unsigned<bool>;
+ template<> struct make_unsigned<bool const>;
+ template<> struct make_unsigned<bool volatile>;
+ template<> struct make_unsigned<bool const volatile>;
/// @cond undocumented
@@ -1932,12 +1937,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Primary template.
/// make_signed
template<typename _Tp>
+#if __cpp_concepts
+ requires is_integral<_Tp>::value || __is_enum(_Tp)
+#endif
struct make_signed
{ typedef typename __make_signed_selector<_Tp>::__type type; };
// Integral, but don't define.
- template<>
- struct make_signed<bool>;
+ template<> struct make_signed<bool>;
+ template<> struct make_signed<bool const>;
+ template<> struct make_signed<bool volatile>;
+ template<> struct make_signed<bool const volatile>;
#if __cplusplus > 201103L
/// Alias template for make_signed
@@ -20,31 +20,28 @@
// <http://www.gnu.org/licenses/>.
#include <type_traits>
-#include <testsuite_character.h>
-enum test_enum { first_selection };
+struct pod_class { };
void test01()
{
using std::make_signed;
// Negative tests.
- typedef make_signed<bool>::type test1_type;
+ using T1 = make_signed<bool>::type; // { dg-error "incomplete" }
+ using T2 = make_signed<const bool>::type; // { dg-error "incomplete" }
+ using T3 = make_signed<volatile bool>::type; // { dg-error "incomplete" }
+ using T4 = make_signed<const volatile bool>::type; // { dg-error "incomplete" }
- typedef make_signed<__gnu_test::pod_uint>::type test2_type;
+ using T5 = make_signed<pod_class>::type; // { dg-error "here" }
- typedef make_signed<int[4]>::type test3_type;
+ using T6 = make_signed<int[4]>::type; // { dg-error "here" }
- typedef void (fn_type) ();
- typedef make_signed<fn_type>::type test4_type;
+ using fn_type = void ();
+ using T7 = make_signed<fn_type>::type; // { dg-error "here" }
- typedef make_signed<float>::type test5_type;
+ using T8 = make_signed<float>::type; // { dg-error "here" }
}
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 }
-// { dg-error "required from here" "" { target *-*-* } 34 }
-// { dg-error "required from here" "" { target *-*-* } 36 }
-// { dg-error "required from here" "" { target *-*-* } 39 }
-// { dg-error "required from here" "" { target *-*-* } 41 }
-
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
+// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
+// { dg-error "constraint failure" "" { target c++20 } 0 }
@@ -21,7 +21,6 @@
#include <type_traits>
-enum test_enum { first_selection };
struct pod_class { };
void test01()
@@ -29,22 +28,20 @@ void test01()
using std::make_unsigned;
// Negative tests.
- typedef make_unsigned<bool>::type test1_type;
+ using T1 = make_unsigned<bool>::type; // { dg-error "incomplete" }
+ using T2 = make_unsigned<const bool>::type; // { dg-error "incomplete" }
+ using T3 = make_unsigned<volatile bool>::type; // { dg-error "incomplete" }
+ using T4 = make_unsigned<const volatile bool>::type; // { dg-error "incomplete" }
- typedef make_unsigned<pod_class>::type test2_type;
+ using T5 = make_unsigned<pod_class>::type; // { dg-error "here" }
- typedef make_unsigned<int[4]>::type test3_type;
+ using T6 = make_unsigned<int[4]>::type; // { dg-error "here" }
- typedef void (fn_type) ();
- typedef make_unsigned<fn_type>::type test4_type;
+ using fn_type = void ();
+ using T7 = make_unsigned<fn_type>::type; // { dg-error "here" }
- typedef make_unsigned<float>::type test5_type;
+ using T8 = make_unsigned<float>::type; // { dg-error "here" }
}
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 32 }
-// { dg-error "required from here" "" { target *-*-* } 34 }
-// { dg-error "required from here" "" { target *-*-* } 36 }
-// { dg-error "required from here" "" { target *-*-* } 39 }
-// { dg-error "required from here" "" { target *-*-* } 41 }
-
-// { dg-error "invalid use of incomplete type" "" { target *-*-* } 0 }
+// { dg-error "invalid use of incomplete type" "" { target c++17_down } 0 }
+// { dg-error "constraint failure" "" { target c++20 } 0 }
@@ -46,4 +46,5 @@ test03()
C c;
std::ssize(c); // { dg-error "no matching function" }
}
-// { dg-error "incomplete type .*make_signed.*S" "" { target *-*-* } 0 }
+// { dg-error "incomplete type .*make_signed.*S" "" { target c++17_down } 0 }
+// { dg-error "constraint failure" "" { target c++20 } 0 }
@@ -51,6 +51,7 @@ proc libstdc++-dg-prune { system text } {
regsub -all "(^|\n)\[^\n\]*: (recursively )?required \[^\n\]*" $text "" text
regsub -all "(^|\n)\[^\n\]*: . skipping \[0-9\]* instantiation contexts \[^\n\]*" $text "" text
regsub -all "(^|\n)\[^\n\]*: in .constexpr. expansion \[^\n\]*" $text "" text
+ regsub -all "(^|\n)\[^\n\]*: in requirements .with\[^\n\]*" $text "" text
regsub -all "(^|\n) inlined from \[^\n\]*" $text "" text
# Why doesn't GCC need these to strip header context?
regsub -all "(^|\n)In file included from \[^\n\]*" $text "" text