<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/107111>107111</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] question about template argument deduction
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rherilier
</td>
</tr>
</table>
<pre>
Hello,
While writing some code for the [libsigc++](https://github.com/libsigcplusplus/libsigcplusplus) project, I faced a case with template code which needed to use #if/else/endif to make it build with gcc, clang and msvc.
I sadly fail to write a testcase without having libsigc++ as a dependency:
```c++
/**
* to build:
* * g++ -std=c++17 main.cpp `pkg-config sigc++-3.0 --cflags --libs`
* * clang++ -std=c++17 main.cpp `pkg-config sigc++-3.0 --cflags --libs`
*/
#include <sigc++/sigc++.h>
#include <cstdio>
template<typename T_return, typename T_obj, typename T_obj2, typename... T_arg>
inline sigc::connection
connect1(sigc::signal<T_return(T_arg...)>& signal, T_obj& obj, T_return (T_obj2::*fun)(T_arg...))
{
printf("connect1<..., T_obj, T_obj2, T_arg...>\n");
return signal.connect(sigc::mem_fun<T_return, T_obj, T_obj2, T_arg...>(obj, fun));
}
template<typename T_return, typename T_obj, typename... T_arg>
inline sigc::connection
connect2(sigc::signal<T_return(T_arg...)>& signal, T_obj& obj, T_return (T_obj::*fun)(T_arg...))
{
printf("connect2<..., T_obj, T_arg...>\n");
return signal.connect(sigc::mem_fun<T_return, T_obj, T_obj, T_arg...>(obj, fun));
}
struct foo
{
void fun(int i) { printf("foo::fun(int %d)\n", i); }
void fun(double d) { printf("foo::fun(double %f)\n", d); }
};
int main()
{
sigc::signal<void(int)> s;
foo f;
connect1(s, f, &foo::fun); // build on gcc and msvc but not clang
connect2(s, f, &foo::fun); // build on gcc and clang but not msvc
s.emit(42);
return 0;
}
```
and the error log is:
```shell
main.cpp:36:3: error: no matching function for call to 'connect1'
connect1(s, f, &foo::fun); // build on gcc and msvc but not clang
^~~~~~~~
main.cpp:11:1: note: candidate template ignored: couldn't infer template argument 'T_obj2'
connect1(sigc::signal<T_return(T_arg...)>& signal, T_obj& obj, T_return (T_obj2::*fun)(T_arg...))
^
1 error generated.
```
Used GCC's versions are 13.3.0 and 14.2.0 while clang's versions are 16.0.6, 17.0.6, 18.1.8, and 19.1.0.
As gcc and msvc success to compile `connect1(s, &foo::fun)`, could it be a limit in clang's template arguments deduction algorithm?
Thanks in advance
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMV0uz2joS_jVi04XLlgDDggWHE2ayz9QsU0Jq20pkibFkUmczv_1Wy-bhA_dRuUnqUkbYcuvrrx-oWzIEUzvELVu-sOXrTPax8d22a7Az1mA3O3r9tv03WusZ37P8leW7YfxvYyzCt85E42oIvkVQXiNUvoPYILDlizXHYGrF-Atdy1fG102Mp8DEjvED44faxKY_Zsq3jB9G6ZPtA32fzWzg1PkvqCLje_gIlVSoQYKSAeGbiQ1EbE9WxpHKt8aoBhyiRg3RQx8QGBemYvyANiD9OG0qetfKrwgmwrE3Vg9gtVKkR1npapBOQxvOKrv3wUcIUts3qKSxBELeQJAQMcQrKd9HaOSZvDRxCMgAEjSe0Gl06o28cofNVvlwXfw3zJLfdnSlR2B8R4oT6ytAmqVvPWqah6iZeB2RihJaaVymTidgq_z0tZ4r7ypTw43cXGQ5zOeqsrIOMJ8Tc6IzxU-u-Xk6yNjRamGcsr1GYGJ_l1P8cHvIGiY-PJNXIWrjby_TeMkUJvbx7YROtgifPncY-85R1O8m_fHL4wy_n8qyDD59ll19VWKcNQ4HY8WOiZ3yzqGKxrtBYHwuGF_fhOi_KC0T-xuTdcLNsozxDaHzFYxSfH_htoKR4mUZpHWJZcJlfFf1jhCmeHwzuqQc0wvg1BkXK8bXjPMrR7FPC_Y3Z9x8cMUTH9hy7xjniekVcGQ0kM5GyInVLbafid692X-qiq_H1xfDbjpZ-fpjIv39YeU_N6w_Iqr8aVR_RSy_P5Qhdr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