[llvm-bugs] [Bug 47780] New: std::visit fails to compile in a specific case with const in visitor return type

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 9 06:48:03 PDT 2020


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: unassignedclangbugs at nondot.org
          Reporter: predelnik at gmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201009/c7445da5/attachment.html>


More information about the llvm-bugs mailing list