1

Consider this piece of code:

template < auto What >
constexpr auto Identity = [](auto&&...) { return What; };

struct Ban
{
  Ban() = default;
  Ban(const Ban&  ban) = delete;
  Ban(      Ban&& ban) = delete;
};

int main()
{ 
  Ban ban;
  Identity<false>(10,ban);

  return 0;
}

This fails to compile on godbolt.org with gcc-7.3 as it tries to copy the second argument of Identity. Why it should? Is this a bug in gcc?

gcc does not complain if the second argument is a temporary or when there is only one argument. It complains for only one argument when the definition of Identity is with (...) instead of (auto&&...).

2
  • Might indeed be a bug, gcc-8 and clang happily compile this. Commented Sep 27, 2018 at 8:09
  • Surprisingly gcc-8 fails when changing (auto&&...) to just (...)! Commented Sep 27, 2018 at 8:12

1 Answer 1

3

The first half is a mis-parse of auto&&... for generic lambdas in older GCC versions: clang vs gcc - empty generic lambda variadic argument pack; Should non-capturing generic lambdas decay to function pointers?; Should non-capturing generic lambdas decay to function pointers?

The second half is expected. Passing over C-style ... variadics makes a copy and you deleted your copy constructor.

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

1 Comment

As a suggestion, include the easy fix: [](auto&&...x) giving the unused pack a name.

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.