Bug 83793 - Pack expansion outside of lambda containing the pack incorrectly rejected
Summary: Pack expansion outside of lambda containing the pack incorrectly rejected
Status: RESOLVED DUPLICATE of bug 47226
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
Depends on:
Reported: 2018-01-11 10:42 UTC by Matthias Kretz (Vir)
Modified: 2018-01-15 14:56 UTC (History)
2 users (show)

See Also:
Known to work: 8.0
Known to fail: 7.2.0
Last reconfirmed: 2018-01-13 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Kretz (Vir) 2018-01-11 10:42:38 UTC
Testcase (https://godbolt.org/g/mNhetZ):

#include <array>
#include <utility>

using std::size_t;
template <size_t... Indexes> auto f(std::index_sequence<Indexes...>) {
    std::array<int, sizeof...(Indexes)> x = {[&]() -> int { return Indexes; }()...};
    return x;

auto g() {
    return f(std::make_index_sequence<3>());

The pack expansion of `[&]() -> int { return Indexes; }()` is apparently never considered. ICC, clang, and MSVC accept the code.
Comment 1 Martin Sebor 2018-01-13 01:04:43 UTC
GCC 8 accepts the code without any errors.

Confirmed with 7.2 and the following output (please remember to provide compiler output with bug reports about wrong diagnostics):

t.C: In lambda function:
t.C:6:68: error: parameter packs not expanded with ‘...’:
     std::array<int, sizeof...(Indexes)> x = {[&]() -> int { return Indexes; }()...};
t.C:6:68: note:         ‘Indexes’
t.C: In function ‘auto f(std::index_sequence<Indexes ...>)’:
t.C:6:80: error: expansion pattern ‘<lambda>()’ contains no argument packs
 td::array<int, sizeof...(Indexes)> x = {[&]() -> int { return Indexes; }()...};

There have been many changes in lambda support in GCC 8.  I'm not sure which one of them has fixed it or whether it would be feasible to backport it to 7.x.  My guess is that it's unlikely.
Comment 2 Jonathan Wakely 2018-01-13 10:26:35 UTC
Looks like a dup of PR 47226 which is already fixed on trunk, but I don't think the recent overhaul of lambda expression handling is suitable to be backported.
Comment 3 Martin Sebor 2018-01-13 17:50:29 UTC
Resolving as a dupe of pr47226 based on comment #2.

*** This bug has been marked as a duplicate of bug 47226 ***
Comment 4 Matthias Kretz (Vir) 2018-01-15 14:56:30 UTC
(In reply to Jonathan Wakely from comment #2)
> Looks like a dup of PR 47226

Ah, yes. Sorry for missing it, I recall seeing it before. I agree, a backport would be nice, but an overhaul is not a backportable bugfix. I really need to switch to GCC 8 just for the lambda fixes. :-)