public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "wangsw.a at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99684] New: [modules] std::visit fails to compile when <variant> is used as header unit Date: Sat, 20 Mar 2021 18:28:07 +0000 [thread overview] Message-ID: <bug-99684-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99684 Bug ID: 99684 Summary: [modules] std::visit fails to compile when <variant> is used as header unit Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wangsw.a at gmail dot com Target Milestone: --- All invocations of std::visit on variants currently fail a static_assert, when <variant> is imported as a header unit. Environment: gcc (GCC) 11.0.1 20210320 (experimental) [master branch], configured with '--enable-languages=c,c++ --disable-multilib', built as docker image on macOS 10.14.6 Dockerfile: https://raw.githubusercontent.com/beanandbean/docker-gcc-cxx-modules/5fa616ae6c55bdb2c2961feff8d8ae5c51004961/Dockerfile [with argument GCC_BRANCH=master] -------- main.cpp -------- import <variant>; int main() { std::variant<int, char> a; std::visit([](auto&&) {}, a); return 0; } ------ command line ------ (in docker shell:) root@1265897bf148:/project# g++ -std=c++20 -fmodules-ts -x c++-system-header variant root@1265897bf148:/project# g++ -std=c++20 -fmodules-ts -Wall -Wextra main.cpp In module /usr/local/include/c++/11.0.1/variant, imported at main.cpp:1: /usr/local/include/c++/11.0.1/variant: In instantiation of '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 = 0; _Tp = std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&)>; _Result_type = std::__detail::__variant::__deduce_visit_result<void>; _Visitor = main()::<lambda(auto:1&&)>&&; long unsigned int ...__dimensions = {2}; _Variants = {std::variant<int, char>&}; long unsigned int ...__indices = {}]': /usr/local/include/c++/11.0.1/variant:944:48: required from 'constexpr const _Array_type std::__detail::__variant::__gen_vtable<std::__detail::__variant::__deduce_visit_result<void>, main()::<lambda(auto:1&&)>&&, std::variant<int, char>&>::_S_vtable' /usr/local/include/c++/11.0.1/variant:1711:45: required from 'constexpr decltype(auto) std::__do_visit(_Visitor&&, _Variants&& ...) [with _Result_type = std::__detail::__variant::__deduce_visit_result<void>; _Visitor = main()::<lambda(auto:1&&)>; _Variants = {std::variant<int, char>&}]' /usr/local/include/c++/11.0.1/variant:1764:34: required from 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = main()::<lambda(auto:1&&)>; _Variants = {std::variant<int, char>&}]' main.cpp:5:30: required from here /usr/local/include/c++/11.0.1/variant:1052:67: in 'constexpr' expansion of 'std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&), 2>, std::integer_sequence<long unsigned int> >::_S_apply()' /usr/local/include/c++/11.0.1/variant:929:19: in 'constexpr' expansion of 'std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&), 2>, std::integer_sequence<long unsigned int> >::_S_apply_all_alts<0, 1>(__vtable, (std::make_index_sequence<2>(), std::make_index_sequence<2>()))' /usr/local/include/c++/11.0.1/variant:966:29: error: static assertion failed: std::visit requires the visitor to have the same return type for all alternatives of a variant 966 | static_assert(is_same_v<_Tp, decltype(__tmp_element)>, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/include/c++/11.0.1/variant:966:29: note: 'std::is_same_v<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&)>, std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&)>&>' evaluates to false /usr/local/include/c++/11.0.1/variant: In instantiation of '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<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&)>; _Result_type = std::__detail::__variant::__deduce_visit_result<void>; _Visitor = main()::<lambda(auto:1&&)>&&; long unsigned int ...__dimensions = {2}; _Variants = {std::variant<int, char>&}; long unsigned int ...__indices = {}]': /usr/local/include/c++/11.0.1/variant:944:48: required from 'constexpr const _Array_type std::__detail::__variant::__gen_vtable<std::__detail::__variant::__deduce_visit_result<void>, main()::<lambda(auto:1&&)>&&, std::variant<int, char>&>::_S_vtable' /usr/local/include/c++/11.0.1/variant:1711:45: required from 'constexpr decltype(auto) std::__do_visit(_Visitor&&, _Variants&& ...) [with _Result_type = std::__detail::__variant::__deduce_visit_result<void>; _Visitor = main()::<lambda(auto:1&&)>; _Variants = {std::variant<int, char>&}]' /usr/local/include/c++/11.0.1/variant:1764:34: required from 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = main()::<lambda(auto:1&&)>; _Variants = {std::variant<int, char>&}]' main.cpp:5:30: required from here /usr/local/include/c++/11.0.1/variant:1052:67: in 'constexpr' expansion of 'std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&), 2>, std::integer_sequence<long unsigned int> >::_S_apply()' /usr/local/include/c++/11.0.1/variant:929:19: in 'constexpr' expansion of 'std::__detail::__variant::__gen_vtable_impl<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&), 2>, std::integer_sequence<long unsigned int> >::_S_apply_all_alts<0, 1>(__vtable, (std::make_index_sequence<2>(), std::make_index_sequence<2>()))' /usr/local/include/c++/11.0.1/variant:966:29: error: static assertion failed: std::visit requires the visitor to have the same return type for all alternatives of a variant /usr/local/include/c++/11.0.1/variant:966:29: note: 'std::is_same_v<std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&)>, std::__detail::__variant::_Multi_array<std::__detail::__variant::__deduce_visit_result<void> (*)(main()::<lambda(auto:1&&)>&&, std::variant<int, char>&)>&>' evaluates to false
next reply other threads:[~2021-03-20 18:28 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-20 18:28 wangsw.a at gmail dot com [this message] 2021-03-30 1:33 ` [Bug c++/99684] " mpolacek at gcc dot gnu.org 2024-03-07 20:44 ` ppalka at gcc dot gnu.org
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-99684-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).