https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101792
Bug ID: 101792 Summary: Compiling access to templated parent object fails with unrelated message: invalid use of 'auto' Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: serpent7776 at gmail dot com Target Milestone: --- Sorry for the title, but I don't know how to describe the issue. The following code fails to compile with error message: <source>: In instantiation of 'int fun(Ts ...) [with Ts = {int, int, int}]': <source>:26:10: required from here <source>:21:41: error: invalid use of 'auto' 21 | return pack.template Value<0, int>::value; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ Compiler returned: 1 The mentioned line doesn't have `auto`, so it's at best a misleading error message. `auto` from error message refers to the `auto` on previous line. Clang compiles the code without issue. If I remove `template` keyword from offending line, gcc compiles the code without issue. gcc 11.2 x86_64 flags: -std=c++17 -Wall -Wextra -pedantic -O2 #include <utility> template <std::size_t, typename T> struct Value { const T& value; }; template <class Idxs, class ...Ts> struct Pack; template <std::size_t ...Idxs, typename ...Ts> struct Pack<std::index_sequence<Idxs...>, Ts...> : Value<Idxs, Ts>... { }; template <typename ...Ts> int fun(Ts... ts) { auto pack = Pack<std::index_sequence_for<Ts...>, Ts...> {{ts}...}; return pack.template Value<0, int>::value; } void f() { fun<>(1, 2, 3); } link to godbolt to see the issue: https://godbolt.org/z/z7so93Wq8