简体   繁体   中英

gcc vs clang: expanding a captured parameter pack twice

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 .

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

GCC 8 compiles the code fine .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM