8

I think I found another "clang vs gcc" inconsistency between lambdas and callable objects.

decltype(l)::operator() should be equivalent to C::operator(), but if variadic pack is left empty in the generic lambda, gcc refuses to compile:

15 : error: no match for call to '(main()::) (int)' l(1);

15 : note: candidate: decltype (((main()::)0u).main()::(x, )) (*)(auto:1&&, auto:2&&, ...)

15 : note: candidate expects 3 arguments, 2 provided

14 : note: candidate: template main()::

auto l = [](auto&& x, auto&&...) { return x; };

14 : note: template argument deduction/substitution failed:

15 : note: candidate expects 2 arguments, 1 provided

l(1);

Live example on godbolt.org.

struct C
{
    template<typename T, typename... TRest>
    auto operator()(T&& x, TRest&&...){ return x; }
};

int main()
{
    // Compiles both with clang and gcc.
    auto c = C{};
    c(1);

    // Compiles with clang 3.7.
    // Does not compile with gcc 5.2.
    auto l = [](auto&& x, auto&&...) { return x; };
    l(1);
}

Could not find anything related to this on the gcc bug tracker (didn't spend too much time searching though) - is gcc wrong here?

1
  • 1
    Looks like a gcc bug. Commented Oct 23, 2015 at 15:21

1 Answer 1

1

I've reported the issue as gcc bug #68071.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.