public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rs2740 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/95904] New: Improve the diagnostic for conflicting return types in std::visit Date: Thu, 25 Jun 2020 23:40:13 +0000 [thread overview] Message-ID: <bug-95904-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2020-06-25 23:40 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-25 23:40 rs2740 at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-95904-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).