]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Enforce requirements on template argument of std::optional
authorJonathan Wakely <jwakely@redhat.com>
Wed, 29 Mar 2023 21:02:19 +0000 (22:02 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 29 Mar 2023 23:06:25 +0000 (00:06 +0100)
commit14f50ba054079eccf9ac49997b92793e2a87b13c
tree03adda7ad1ed84f458d6709b6d8f01713d875af2
parent68982b98d2a7a52cfc5aada7d35d6c493c010712
libstdc++: Enforce requirements on template argument of std::optional

The standard does not allow std::optional<T&>, std::optional<T[1]>,
std::optional<T()> etc. and although we do give errors, they come from
down inside the internals of std::optional. We could improve the static
assertions at the top of the class so that users get a more precise
diagnostic:

optional:721:21: error: static assertion failed
721 |       static_assert(is_object_v<_Tp> && !is_array_v<_Tp>);

libstdc++-v3/ChangeLog:

* include/std/optional (optional): Adjust static assertion to
reject arrays and functions as well as references.
* testsuite/20_util/optional/requirements_neg.cc: New test.
libstdc++-v3/include/std/optional
libstdc++-v3/testsuite/20_util/optional/requirements_neg.cc [new file with mode: 0644]
This page took 0.060847 seconds and 6 git commands to generate.