4

Consider this code snippet:

int main () {
    auto first = [&] (auto... one) {
        auto faulty = [&] () {
            [[maybe_unused]] auto i = (one + ...);
            return (one + ...);
        };
        faulty();
    };
    first(1);
}

See also on godbolt.

It seems that when I try to expand the implicitly captured parameter pack one twice inside the inner lambda, gcc complains, but clang does not. Note that when I explicitly capture, like so [&one...], gcc doesn't complain anymore.

To me this looks like a gcc bug, but I would like some confirmation from people who are more experienced than me, since I have already seen (different) buggy behaviour in clang with variadic captures here.

L. F.
  • 19,445
  • 8
  • 48
  • 82
nnolte
  • 1,628
  • 11
  • 25
  • 4
    How is this different from your previous question https://stackoverflow.com/questions/56356708/clang-vs-gcc-variadic-lambda-captures? – L. F. Jun 02 '19 at 11:03
  • 2
    1. gcc complains here, clang complained before 2. it occurs in different scenarios 3. the compiler error is different. The only thing that is identical is that `[&one...]` seems to fix it :D – nnolte Jun 02 '19 at 11:05
  • 1
    I suggest that you link to your previous question and explain the difference because they are similar. Otherwise people who have saw your previous question (like me) may be confused. – L. F. Jun 02 '19 at 11:06
  • i assume these are quite different, but alright – nnolte Jun 02 '19 at 11:09
  • Why the downvote? The OP has clarified that this is not a repost of the previous question. – L. F. Jun 02 '19 at 11:20

1 Answers1

1

This is a regression in GCC 9. It has been reported.

GCC 8 compiles the code fine.

L. F.
  • 19,445
  • 8
  • 48
  • 82