https://bugs.llvm.org/show_bug.cgi?id=47780
Bug ID: 47780
Summary: std::visit fails to compile in a specific case with
const in visitor return type
Product: libc++
Version: 11.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
The following program:
#include <variant>
class X
{
};
class PseudoIt
{
public:
X operator* () { return X{};}
};
int main ()
{
std::variant<PseudoIt, X*> v;
// commenting out const below VVV fixes the error
std::visit ([](auto &&x) -> const X { return *x; }, v);
}
fails to compile with current trunk libc++. Here's only the final bit of
obviously long compilation stack:
/opt/compiler-explorer/clang-trunk-20201009/bin/../include/c++/v1/variant:502:12:
error: address of overloaded function '__dispatch' does not match required type
'const X
(std::__1::__variant_detail::__visitation::__variant::__value_visitor<(lambda
at <source>:17:17)> &&,
std::__1::__variant_detail::__base<std::__1::__variant_detail::_Trait::_TriviallyAvailable,
PseudoIt, X *> &)'
return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>;
Removing const in lambda return type fixes the compilation. Other variant
implementations work fine in such case.
godbolt link for convenience:
https://gcc.godbolt.org/z/5q4s1d
I've got this const in some template code and it was not necessary in any way
but still I think code like this should compile.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs