public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit
@ 2020-06-25 23:40 rs2740 at gmail dot com
2020-06-26 0:26 ` [Bug libstdc++/95904] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: rs2740 at gmail dot com @ 2020-06-25 23:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95904
Bug ID: 95904
Summary: Improve the diagnostic for conflicting return types in
std::visit
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: rs2740 at gmail dot com
Target Milestone: ---
std::variant<int, long> x;
std::visit([] (auto i) { return i; }, x);
produces a less than ideal error with libstdc++:
In file included from <source>:1:
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant: In
instantiation of 'static constexpr auto
std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<_Result_type
(*)(_Visitor, _Variants ...)>, std::integer_sequence<long unsigned int,
__indices ...> >::_S_apply() [with _Result_type =
std::__detail::__variant::__deduce_visit_result<int>; _Visitor =
main()::<lambda(auto:22)>&&; _Variants = {std::variant<int, long int>&}; long
unsigned int ...__indices = {1}]':
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:962:56:
required from 'static constexpr void
std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<_Result_type
(*)(_Visitor, _Variants ...), __dimensions ...>, std::integer_sequence<long
unsigned int, __indices ...> >::_S_apply_single_alt(_Tp&, _Tp*) [with bool
__do_cookie = false; long unsigned int __index = 1; _Tp =
std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<int>
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&)>; _Result_type =
std::__detail::__variant::__deduce_visit_result<int>; _Visitor =
main()::<lambda(auto:22)>&&; long unsigned int ...__dimensions = {2}; _Variants
= {std::variant<int, long int>&}; long unsigned int ...__indices = {}]'
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:941:48:
required from 'constexpr const _Array_type
std::__detail::__variant::__gen_vtable<std::__detail::__variant::__deduce_visit_result<int>,
main()::<lambda(auto:22)>&&, std::variant<int, long int>&>::_S_vtable'
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:1685:45:
required from 'constexpr decltype(auto) std::__do_visit(_Visitor&&, _Variants&&
...) [with _Result_type = std::__detail::__variant::__deduce_visit_result<int>;
_Visitor = main()::<lambda(auto:22)>; _Variants = {std::variant<int, long
int>&}]'
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:1704:35:
required from 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...)
[with _Visitor = main()::<lambda(auto:22)>; _Variants = {std::variant<int, long
int>&}]'
<source>:5:43: required from here
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:1028:67:
in 'constexpr' expansion of
'std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<int>
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&), 2>,
std::integer_sequence<long unsigned int> >::_S_apply()'
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:926:19:
in 'constexpr' expansion of
'std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<int>
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&), 2>,
std::integer_sequence<long unsigned int> >::_S_apply_all_alts<0, 1>(__vtable,
(std::make_index_sequence<2>(), std::make_index_sequence<2>()))'
/opt/compiler-explorer/gcc-trunk-20200625/include/c++/11.0.0/variant:1017:43:
error: invalid conversion from 'std::__success_type<long int>::type
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&)' {aka 'long int
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&)'} to
'std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<int>
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long
int>&)>::__untag_result<std::__detail::__variant::__deduce_visit_result<int>
(*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&)>::element_type'
{aka 'int (*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&)'}
[-fpermissive]
1017 | { return _Array_type{&__visit_invoke}; }
| ^
| |
| std::__success_type<long
int>::type (*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&) {aka
long int (*)(main()::<lambda(auto:22)>&&, std::variant<int, long int>&)}
Not only is the error about type mismatch in some function pointer conversion
deep in the guts of the library, but it even offers a "helpful" option to
suppress it with -fpermissive...
Both MSVC and libc++ handle this case with a nice static_assert.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/95904] Improve the diagnostic for conflicting return types in std::visit
2020-06-25 23:40 [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit rs2740 at gmail dot com
@ 2020-06-26 0:26 ` redi at gcc dot gnu.org
2020-06-29 11:13 ` ville.voutilainen at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-26 0:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95904
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2020-06-26
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/95904] Improve the diagnostic for conflicting return types in std::visit
2020-06-25 23:40 [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit rs2740 at gmail dot com
2020-06-26 0:26 ` [Bug libstdc++/95904] " redi at gcc dot gnu.org
@ 2020-06-29 11:13 ` ville.voutilainen at gmail dot com
2020-10-09 17:49 ` cvs-commit at gcc dot gnu.org
2020-10-09 17:50 ` ville.voutilainen at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-06-29 11:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95904
Ville Voutilainen <ville.voutilainen at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ville.voutilainen at gmail dot com
Status|NEW |ASSIGNED
CC| |ville.voutilainen at gmail dot com
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/95904] Improve the diagnostic for conflicting return types in std::visit
2020-06-25 23:40 [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit rs2740 at gmail dot com
2020-06-26 0:26 ` [Bug libstdc++/95904] " redi at gcc dot gnu.org
2020-06-29 11:13 ` ville.voutilainen at gmail dot com
@ 2020-10-09 17:49 ` cvs-commit at gcc dot gnu.org
2020-10-09 17:50 ` ville.voutilainen at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-09 17:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95904
--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Ville Voutilainen <ville@gcc.gnu.org>:
https://gcc.gnu.org/g:3427e31331677ca826c5588c87924214f7e5c54b
commit r11-3760-g3427e31331677ca826c5588c87924214f7e5c54b
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Fri Oct 9 20:47:01 2020 +0300
libstdc++: Diagnose visitors with different return types [PR95904]
libstdc++-v3/ChangeLog:
PR libstdc++/95904
* include/std/variant (__deduce_visit_result): Add a nested ::type.
(__gen_vtable_impl</*base case*/>::_S_apply):
Check the visitor return type.
(__same_types): New.
(__check_visitor_result): Likewise.
(__check_visitor_results): Likewise.
(visit(_Visitor&&, _Variants&&...)): Use __check_visitor_results
in case we're visiting just one variant.
* testsuite/20_util/variant/visit_neg.cc: Adjust.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/95904] Improve the diagnostic for conflicting return types in std::visit
2020-06-25 23:40 [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit rs2740 at gmail dot com
` (2 preceding siblings ...)
2020-10-09 17:49 ` cvs-commit at gcc dot gnu.org
@ 2020-10-09 17:50 ` ville.voutilainen at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-10-09 17:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95904
Ville Voutilainen <ville.voutilainen at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #2 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
There are aspirations to change the variant tables to a flat one, but that's a
separate enhancement. This particular problem is fixed.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-09 17:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-25 23:40 [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit rs2740 at gmail dot com
2020-06-26 0:26 ` [Bug libstdc++/95904] " redi at gcc dot gnu.org
2020-06-29 11:13 ` ville.voutilainen at gmail dot com
2020-10-09 17:49 ` cvs-commit at gcc dot gnu.org
2020-10-09 17:50 ` ville.voutilainen at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).