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

            Bug ID: 90609
           Summary: Compilation error in std::function default member
                    initialization inside template class with defaulted
                    constructor
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tgolyi at ya dot ru
  Target Milestone: ---

When compiling the following code in gcc 9.1 compilation fails

#include <functional>
#include <memory>

template<typename T>
struct test
{
  std::function<void(T *)> f = [](T *) {};
};

struct test2
{
  test<double> d;
  test<int> i;
};

void g ()
{
  std::make_unique<test2> ();
}

Error is:
<source>:7:32: error: could not convert '<lambda closure
object>test<double>::<lambda(double*)>{}' from
'test<double>::<lambda(double*)>' to 'std::function<void(int*)>'

    7 |   std::function<void(T *)> f = [](T *) {};

      |                                ^~~~~~~~~~

      |                                |

      |                                test<double>::<lambda(double*)>

If you provide empty constructor to test class everything works fine.

Reply via email to