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

            Bug ID: 118324
           Summary: Type deduction for class with deleted copy constructor
                    failed in lambda parameter
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wangbopku15 at gmail dot com
  Target Milestone: ---

Consider the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

struct A {   
    A(const A&) = delete;
};

void (*fptr)(A) = [](auto){};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

GCC rejects it with a confusing diagnostic that complains about bad type
conversion:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<source>:5:19: error: cannot convert '<lambda(auto:1)>' to 'void (*)(A)' in
initialization
    5 | void (*fptr)(A) = [](auto){};
      |                   ^~~~~~~~~~
      |                   |
      |                   <lambda(auto:1)>
Compiler returned: 1

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Note that the 'auto' parameter can be correctly deduced to 'A' if the copy ctor
of 'A' is not deleted.

EDG, clang, and ICC accept that:

https://godbolt.org/z/c87dn9GcG

Reply via email to