https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97277

            Bug ID: 97277
           Summary: Lambda in fold expressions capture arguments are
                    default initialized
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cusimr at amazon dot com
  Target Milestone: ---

https://godbolt.org/z/69ah91

#include <tuple>
#include <iostream>

struct Index {
    size_t i;
};

int main() {
    std::tuple<int, float, double, size_t> t{1, 2.f, 3, 4};

    Index i{1};
    std::apply([i](auto&& ...args) {
        (..., [i](auto&& arg) { std::cout << arg + i.i << "\n"; }(args));
    }, t);

}

g++ -std=c++17

Expected Output:
2, 3, 4, 5

Actual Output:
2, 2, 3, 4

This bit me today and I found this on Ubuntu 18.04 LTS. I realize this is fixed
as of 8.1 but Ubuntu 18.04 LTS is supported until 2023 meaning it's likely this
bug will persist in the wild for at least 3 more years. Not sure if I should
report this as a bug to Ubuntu or if there's a possibility of a backport fix to
7.5 or even a new 7.6 release.

Reply via email to