diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-08-23 15:46:16 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-08-23 16:35:07 +0100 |
commit | e85bb1881e57e53306ede2a15f30d06480d69886 (patch) | |
tree | c014f13ccd8023fd1c0d05780fdc5a3ba0fb53f7 /libstdc++-v3/testsuite | |
parent | aeb9b58225916bc84a0cd02c6fc77bbb92167e53 (diff) | |
download | gcc-e85bb1881e57e53306ede2a15f30d06480d69886.zip gcc-e85bb1881e57e53306ede2a15f30d06480d69886.tar.gz gcc-e85bb1881e57e53306ede2a15f30d06480d69886.tar.bz2 |
libstdc++: Fix visit<void>(v) for non-void visitors [PR106589]
The optimization for the common case of std::visit forgot to handle the
edge case of passing zero variants to a non-void visitor and converting
the result to void.
libstdc++-v3/ChangeLog:
PR libstdc++/106589
* include/std/variant (__do_visit): Handle is_void<R> for zero
argument case.
* testsuite/20_util/variant/visit_r.cc: Check std::visit<void>(v).
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r-- | libstdc++-v3/testsuite/20_util/variant/visit_r.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/variant/visit_r.cc b/libstdc++-v3/testsuite/20_util/variant/visit_r.cc index 712459f..c77b259 100644 --- a/libstdc++-v3/testsuite/20_util/variant/visit_r.cc +++ b/libstdc++-v3/testsuite/20_util/variant/visit_r.cc @@ -54,10 +54,18 @@ void test02() std::visit<const void>(Visitor(), v); } +void test03() +{ + // PR libstdc++/106589 - visit<void> rejects lambdas that do not return void + auto visitor = []{ return 0; }; + std::visit<void>(visitor); + std::visit<void>(static_cast<int(*)()>(visitor)); +} int main() { test01(); test02(); + test03(); } |