<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/115897>115897</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Complains on uneeded copy ctor in lambda substitution through template parameter pack
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          OscarDibert
      </td>
    </tr>
</table>

<pre>
    Let's consider the following code:

```
$more znort.cpp
 #include <iostream>
#include <functional>

struct znort {
  znort(znort const&) = delete;
 znort(bool v) : b(v) {};
  bool b;
};

auto wrap(znort const& z) { return &z; }
template<typename T> T const& wrap(T const& z) { return z; }

template<typename... Arg> bool probe(znort const& z, Arg...) { return z.b; }
template<typename... Arg> bool probe(znort const* z, Arg...) { return z->b; }
template<typename T, typename... Arg> bool probe(T t, Arg... arg) { return probe(arg...); }
  

template<typename... Arg>
std::function<bool(Arg...)>
f() {
  return [](Arg... arg) {
 bool b1 = probe(wrap(arg)...);    // THIS IS LINE 22 => FINE
    bool b2 = probe(arg...);              // THIS IS LINE 23 => NOT FINE
    return b1&&b2;
  };
}

int main() {
  znort z{true};
  return f<int, znort const&, bool>()(2,z,true) ? 0 : 42;
}
 
```

```
$:~/view/fargOCA/gpu/seq/llvm/dbg$clang++-18 ./znort.cpp
 $clang++-18 ./znort.cpp
./znort.cpp:23:21: error: call to deleted constructor of 'znort'
   23 |     bool b2 = probe(arg...);
 |                     ^~~
./znort.cpp:21:25: note: while substituting into a lambda expression here
   21 |   return [](Arg... arg) {
      | ^
./znort.cpp:30:10: note: in instantiation of function template specialization 'f<int, const znort &, bool>' requested here
   30 |   return f<int, znort const&, bool>()(2,z,true) ? 0 : 42;
 |          ^
./znort.cpp:5:3: note: 'znort' has been explicitly marked deleted here
    5 |   znort(znort const&) = delete;
      | ^
./znort.cpp:15:62: note: passing argument to parameter 'arg' here
 15 | template<typename T, typename... Arg> bool probe(T t, Arg... arg) { return probe(arg...); }
      | ^
1 error generated.
```

The code does not require the znort copy constructor in line 22 nor 23, but the compiler complains at line 23.
Note that I only get the problem whe the substitution is requested through a template pack.

I am doing something wrong or is there an issue in the substitution phase ?

Thanks
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVt9uo7oTfhrnZrQI7CSkF7lI0qJfpVX3YvMCBibg3xqbtU1z2os--5ENNNC02x7pSCeKEH_G33wz883Y3FpRKcQtWe3J6nbBO1drs_1hC25uRY7GLXJdPm2_oyM0tVBoZUWJBlyNcNJS6rNQFRS6RMJ2JL4l8Xhdx8O_f6TLRhuEZ6WNi4q27V8DoUyoQnYlAmEHoa0zyBvC7sZl08-nThVOaMXlxSBcrTNd4XpwIOl-AO9fELrpP3jyjtA1oTdA2C2UKNEhYaP5aJ1rLeGxt9pBTuimf0j3JL29mEOwy19fTD_2V945DWfD2ysK8DwggkHXGQWErp8J24MHCWsdNq3knt7BPbWoeINwJOwOjheQAfr4Mewc80PkKIpgZyoPH4Jqjc7xXdIHbxdF0Vs_Uf4Z-y_52P3JxzfC7j51A0cP8JnTI7iLH-CmeuNrtOMjkZlbgC_nc9Rn6duD7UYFE3bwfAjd7C4eBuMToZtRb4O7USShSV8XTXgPhr0ik6DuMYRBJL3tJRgAIDQjNIPj_-5_wv1P-H7_cAeU-sU-X9n9w93of9Q6nSHPkjP7vYvMRuSHH8c36EN8eRK6c53TSZfN2mquZKEcNFyo64T1onom6d6ZDudtOzg7-XmjggzejodDCNcXJAATuqGEHrwyA1oYDBnEYTws6TU7eH8EfjAXCdu9EJo9CjwTmp24qX4cdoRmVdsRmln8TWgm5WNDaFbmFaHLQnJVEbondP8t2UBEaHY9Vr9gNX_FdpT5S-KjQmO08TcFlxKcHmZl2SfJD1ttQJ-A0HSYmulrNX2h0wN8RTUj28H87Y-s7l5ePuDqadKVp6i0770dnGshEWyXWydc5_y-JJTTwEHyJi854F-tQWuFVlC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