[Bug c++/126796] New: [c++26] "cannot index an empty pack" on uninstantiated function

marcel at laverdet dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126796

            Bug ID: 126796
           Summary: [c++26] "cannot index an empty pack" on uninstantiated
                    function
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcel at laverdet dot com
  Target Milestone: ---

a.cc:
template <class...Types>
struct foo {
  template <int Index>
  auto get() const -> Types...[Index] { return {}; }
};

auto main() -> int {
  auto ff = foo<>{};
  return 0;
}

---

$ g++ --version
g++ (GCC) 16.2.0
Copyright (C) 2026 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ -std=c++2c a.cc 
a.cc: In instantiation of ‘struct foo<>’:
a.cc:8:18:   required from here
    8 |         auto ff = foo<>{};
      |                         ^
a.cc:4:14: error: cannot index an empty pack
    4 |         auto get() const -> Types...[Index] { return {}; }
      |              ^~~

$ clang++ -std=c++2c a.cc 
// it's fine

---

Replacing with `auto get() const -> auto { return Types...[Index]{}; }` works.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.