hctim added a comment. Hi folks,
I found an issue with building Android using this patch. I've reduced it down to the following problem where the evaluation of the `std::visit` is believed to be non-exhaustive, but it seems like it is? Would you mind taking a look? Admittedly, my knowledge in this area of the cxx stdlib is not so great. Thanks. $ cat /tmp/variant.cpp #include <utility> #include <variant> struct A {}; struct B {}; using MyVariant = std::variant<A, B>; // Helper to std::visit with lambdas. template <typename... V> struct Visitor : V... {}; // explicit deduction guide (not needed as of C++20) template <typename... V> Visitor(V...) -> Visitor<V...>; const char* toString(const MyVariant& args) { Visitor toStringVisitor{ [&](const A&) { return "A"; }, [&](const B&) { return "B"; }, }; return std::visit(toStringVisitor, args); } $ ~/llvm-build/opt/bin/clang++ /tmp/variant.cpp -c -o /tmp/variant.o -std=c++17 -stdlib=libc++ In file included from /tmp/variant.cpp:2: /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:680:19: error: static assertion failed due to requirement 'is_invocable_v<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const A &>': `std::visit` requires the visitor to be exhaustive. 680 | static_assert(is_invocable_v<_Visitor, _Values...>, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:689:7: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__std_visit_exhaustive_visitor_check<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const A &>' requested here 689 | __std_visit_exhaustive_visitor_check< | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__type_traits/invoke.h:337:10: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>::operator()<const std::__variant_detail::__alt<0, A> &>' requested here 337 | decltype(std::declval<_Fp>()(std::declval<_Args>()...)) | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:572:16: note: while substituting deduced template arguments into function template '__invoke' [with _Fp = std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, _Args = <const __alt<0UL, A> &>] 572 | return _VSTD::__invoke( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__config:805:17: note: expanded from macro '_VSTD' 805 | # define _VSTD std | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:581:43: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__dispatcher<0>::__dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 581 | return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>; | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:608:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 608 | return __make_dispatch<_Fp, _Vs...>(__is); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:616:34: note: (skipping 2 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all) 616 | return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:533:9: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 533 | __make_fmatrix<_Visitor&&, | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:642:20: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::__variant_detail::__impl<A, B> &>' requested here 642 | return __base::__visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:661:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::variant<A, B> &>' requested here 661 | return __visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:1759:21: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_value<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &>' requested here 1759 | return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), | ^ /tmp/variant.cpp:21:17: note: in instantiation of function template specialization 'std::visit<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &, void>' requested here 21 | return std::visit(toStringVisitor, args); | ^ In file included from /tmp/variant.cpp:2: /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:692:14: error: attempt to use a deleted function 692 | return _VSTD::__invoke(_VSTD::forward<_Visitor>(__visitor), | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__config:805:17: note: expanded from macro '_VSTD' 805 | # define _VSTD std | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__type_traits/invoke.h:337:10: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>::operator()<const std::__variant_detail::__alt<0, A> &>' requested here 337 | decltype(std::declval<_Fp>()(std::declval<_Args>()...)) | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:572:16: note: while substituting deduced template arguments into function template '__invoke' [with _Fp = std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, _Args = <const __alt<0UL, A> &>] 572 | return _VSTD::__invoke( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__config:805:17: note: expanded from macro '_VSTD' 805 | # define _VSTD std | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:581:43: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__dispatcher<0>::__dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 581 | return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>; | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:608:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 608 | return __make_dispatch<_Fp, _Vs...>(__is); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:616:34: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix_impl<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 616 | return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:623:12: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all) 623 | return __make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:533:9: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 533 | __make_fmatrix<_Visitor&&, | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:642:20: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::__variant_detail::__impl<A, B> &>' requested here 642 | return __base::__visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:661:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::variant<A, B> &>' requested here 661 | return __visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:1759:21: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_value<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &>' requested here 1759 | return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), | ^ /tmp/variant.cpp:21:17: note: in instantiation of function template specialization 'std::visit<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &, void>' requested here 21 | return std::visit(toStringVisitor, args); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__type_traits/nat.h:25:3: note: '~__nat' has been explicitly marked deleted here 25 | ~__nat() = delete; | ^ In file included from /tmp/variant.cpp:2: /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:572:16: error: attempt to use a deleted function 572 | return _VSTD::__invoke( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__config:805:17: note: expanded from macro '_VSTD' 805 | # define _VSTD std | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:581:43: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__dispatcher<0>::__dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 581 | return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>; | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:608:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 608 | return __make_dispatch<_Fp, _Vs...>(__is); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:616:34: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix_impl<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 616 | return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:623:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix_impl<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL, 1UL>' requested here 623 | return __make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:533:9: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 533 | __make_fmatrix<_Visitor&&, | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:642:20: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::__variant_detail::__impl<A, B> &>' requested here 642 | return __base::__visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:661:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::variant<A, B> &>' requested here 661 | return __visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:1759:21: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_value<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &>' requested here 1759 | return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), | ^ /tmp/variant.cpp:21:17: note: in instantiation of function template specialization 'std::visit<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &, void>' requested here 21 | return std::visit(toStringVisitor, args); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/__type_traits/nat.h:25:3: note: '~__nat' has been explicitly marked deleted here 25 | ~__nat() = delete; | ^ In file included from /tmp/variant.cpp:2: /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:581:12: error: cannot deduce return type 'auto' from returned value of type '<overloaded function type>' 581 | return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>; | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:608:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_dispatch<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 608 | return __make_dispatch<_Fp, _Vs...>(__is); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:616:34: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix_impl<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL>' requested here 616 | return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:623:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix_impl<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &, 0UL, 1UL>' requested here 623 | return __make_fmatrix_impl<_Fp, _Vs...>( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:533:9: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__make_fmatrix<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &> &&, const std::__variant_detail::__base<std::__variant_detail::_Trait::_TriviallyAvailable, A, B> &>' requested here 533 | __make_fmatrix<_Visitor&&, | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:642:20: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__base::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::__variant_detail::__impl<A, B> &>' requested here 642 | return __base::__visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:661:12: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_alt<std::__variant_detail::__visitation::__variant::__value_visitor<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &>, const std::variant<A, B> &>' requested here 661 | return __visit_alt( | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:1759:21: note: in instantiation of function template specialization 'std::__variant_detail::__visitation::__variant::__visit_value<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &>' requested here 1759 | return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor), | ^ /tmp/variant.cpp:21:17: note: in instantiation of function template specialization 'std::visit<Visitor<(lambda at /tmp/variant.cpp:18:13), (lambda at /tmp/variant.cpp:19:13)> &, const std::variant<A, B> &, void>' requested here 21 | return std::visit(toStringVisitor, args); | ^ /usr/local/google/home/mitchp/llvm-build/opt/bin/../include/c++/v1/variant:571:37: note: candidate template ignored: failed template argument deduction 571 | static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) { | ^ 4 errors generated. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D155387/new/ https://reviews.llvm.org/D155387 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits