https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95328

            Bug ID: 95328
           Summary: structured binding of template type inside template
                    function is reported as "incomplete class type"
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefaan.deroeck at gmail dot com
  Target Milestone: ---

A structured binding assignment of a template type inside a template function
seems to be reported as "incomplete class type". 

Compiling below code apparently produces the warning (and thus failure with
-Werror) on all applicable GCC versions (gcc-7 segfaults, gcc-8 and up
including 11 reports the warning). Clang and intel compilers compile this
without warnings. 

This is the minimal code with which I can reproduce the issue. Removal of any
of the templating, or replacing the return type of makeData() by "auto", gets
rid of the warning. 

compilation flags: -std=c++17 -Werror

Reported error:
<source>: In function 'void func()':
<source>:14:8: error: structured binding refers to incomplete class type
'Data<int>' [-Werror]
   14 |   auto [a, b] = makeData<int>();
      |        ^~~~~~
cc1plus: all warnings being treated as errors



Code:
template <typename T>
struct Data
{
  int a, b;
};
template <typename T>
Data<T> makeData()
{
  return Data<T>();
}
template <class Anything>
void func()
{
  auto [a, b] = makeData<int>();
}
int main() { func<int>(); }

Reply via email to