[llvm-bugs] [Bug 24989] New: Regression: Lambda with no return behaves differently from lambda with empty return

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 29 13:52:22 PDT 2015


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

            Bug ID: 24989
           Summary: Regression: Lambda with no return behaves differently
                    from lambda with empty return
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kenton at sandstorm.io
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The code below worked in Clang 3.6 but fails to compile in 3.7. This in
particular is breaking some code that uses Cap'n Proto.

It appears Clang 3.7 treats "[]()(auto) {}" differently from "[]()(auto)
{return;}", even though they are clearly equivalent. In the former case, in
some scenarios (but not all), it fails to recognize that the return type is
"void".

==== TEST CASE ====

// compile with:
//   clang --std=c++14 -c test.cc

template <typename R, typename C, typename P>
void match(R (C::*p)(P) const) {}

template <typename Func>
void matchFunctor(Func&& func) {
  typedef decltype(func(1)) ReturnType;
  match<ReturnType, Func, int&&>(&Func::operator());
}

void f() {
  matchFunctor([](auto) {});          // ERROR in clang 3.7, works in 3.6-
  matchFunctor([](auto) {return;});   // works in all versions
}

=== OUTPUT ===

test.cc:10:3: error: no matching function for call to 'match'
  match<ReturnType, Func, int&&>(&Func::operator());
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cc:14:3: note: in instantiation of function template specialization
'matchFunctor<(lambda at test.cc:14:16)>' requested here
  matchFunctor([](auto) {});          // ERROR in clang 3.7, works in 3.6-
  ^
test.cc:5:6: note: candidate function [with R = void, C = (lambda at
test.cc:14:16), P = int &&] not viable: no overload of 'operator()' matching
      'void ((lambda at test.cc:14:16)::*)(int &&) const' for 1st argument
void match(R (C::*p)(P) const) {}
     ^
1 error generated.

-- 
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/20150929/f89b050f/attachment.html>


More information about the llvm-bugs mailing list