https://bugs.llvm.org/show_bug.cgi?id=39911

            Bug ID: 39911
           Summary: Lambda call operator invoked if streamed to std::cout
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

Consider the following code:

int main()
{
    auto lam = [](auto x) {return x*2;};
    std::cout << lam; // fails with: "error: invalid operands to binary
expression ('std::basic_ostream<char>' and 'int')"
}

If a lambda is passed to std::cout compilation does not fail as expected. It
fails but for the wrong reason ("invalid operands to binary expression, rather
than "no matching function call"). It seems that the call operator is
instantiated (and called with iostream as input) somewhere in the overload
resolution. I think that this is not correct. The problem in my use case is,
that this breaks expression sfinae. 

See the more comprehensive example here: https://godbolt.org/z/-6fz0o

The code works as expected with gcc and msvc, so I guess it's a clang problem.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to