[llvm-bugs] [Bug 39911] New: Lambda call operator invoked if streamed to std::cout

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 7 03:16:18 PST 2018


            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: unassignedclangbugs at nondot.org
          Reporter: golka.gerald at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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

More information about the llvm-bugs mailing list