https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102590
Bug ID: 102590 Summary: Templated operations on variables in structured binding don't work when templated functions/lambdas require type deduction Product: gcc Version: 8.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: 1997.rajatjain at gmail dot com Target Milestone: --- Foreach loops written with a structured-binding declaration error out if any of the captured types contains a template member-function which is used inside the loop. This only happens if such a loop is placed inside a templated lambda/function. A minimal example of the above is: struct Foo { template<typename T> T get() const { return static_cast<T>(0); } }; template<typename T> void error_func(T elem) { std::array<std::pair<int, Foo>, 1> arr; for(const auto& [_, val] : arr) { val.get<int>(); // Error here } } The error disappears if T is replaced with any concrete type. It also disappears if instead of structured bindings, a tuple is used with auto type specifier. The above code also works if one writes: const auto& [_, val] = arr[0]; val.get<int>(); Compilation flags: -std=c++17 Reported error: test.cpp:19:17: error: expected primary-expression before 'int' val.get<int>(); ^~~ test.cpp:19:17: error: expected ';' before 'int' val.get<int>(); ^~~ ;