<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68849>68849</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
private member function in the template specialization does not sfinae out overload
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tchaikov
</td>
</tr>
</table>
<pre>
i notice that following program fails to compile:
```c++
template <typename> struct templ_foo;
template <> class templ_foo<int> {
void bar_func(bool);
};
template <typename> struct templ_bar;
template <> class templ_bar<bool> {
public:
template <class U>
auto maybe_call_foo(U u, bool set)
-> decltype(u.bar_func(set)) {
u.bar_func(set);
}
template <class U> void maybe_call_foo(U...);
};
template <class U>
auto maybe_call_foo(U u, bool set)
-> decltype(u.bar_func(set)) {
u.bar_func(set);
}
template <class U> void maybe_call_foo(U...);
void parse_format_specs() {
templ_foo<int> foo_int;
#define GLOBAL_OVERLOAD 0
#if GLOBAL_OVERLOAD
maybe_call_foo(foo_int, true);
#else
templ_bar<bool> foo_bool;
foo_bool.maybe_call_foo(foo_int, true);
#endif
}
```
when i compile it using Clang (tested with clang-16, clang-17 and the latest clang trunk):
```console
$ clang++ -Werror -c -std=c++20 test.cc
test.cc:12:7: error: 'bar_func' is a private member of 'templ_foo<int>'
u.bar_func(set);
^
test.cc:33:12: note: in instantiation of function template specialization
'templ_foo<bool>::maybe_call_foo<templ_foo<int>>' requested here
foo_bool.maybe_call_foo(foo_int, true);
^
test.cc:4:8: note: implicitly declared private here
void bar_func(bool);
^
test.cc:11:21: error: 'bar_func' is a private member of 'templ_foo<int>'
-> decltype(u.bar_func(set)) {
^
test.cc:4:8: note: implicitly declared private here
void bar_func(bool);
^
2 errors generated.
```
but if i
```c++
#define GLOBAL_OVERLOAD 1
```
the source code compiles. the same source code compiles with gcc 13.2.1.
my guess is that clang fails to take the member access check into consideration if the member is accessed by the template specialization of the same template. in this case, both full specialization specialize the template of `templ_foo` with `int` and `bool` respectively. if i declare another template `templ_baz`, and specialize it using `bool`, and then define the same overloads in it, clang is able to sfinae out the overload accessing the private member function.
the reproducer is also available at godbolt. see https://godbolt.org/z/EW6EPPqz3
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0V11v4jgX_jXm5ogosWmACy4YWt6bkTp6pdm5RI5zQrx14oztUNFfv7Lz0UBbdrqzO0JTE5-v55zHTwy3Vh5rxA25-0Lu7me8daU2GydKLp_0aZbp_LyRUGsnBYIruYNCK6WfZX2Exuij4RUUXCoLToPQVSMVErYl8T2JtySNu48g9Iv_hKcOq0Zxh0DYzp0brHmFhD2AdaYVDsL2odCasN7hrZs3F4pbO7Xeydr5DbLs_QBOWuaQcXMo2loQusq0VoSuXyMv729k-bC4jJtPFBesdyH1tLqmzZQUY68ApjE6_--EPQy7vHUaKn7O8CC46iDT1XdoCd2BDw4WncfW2_t_c58wR6E8EkJXbTTpRW9O19OGAbxnM2AF36-b1XYdf1tmFEW_3vdr8J-H_nngt2CPqH8Pc_g_2DbcWDwU2lTcHWyDwhK6uizoHV4XWh_C8iIgoSzHQtYI__v6-GX79fD4x8P_vz5u7yG-MpPFtckA_k3tQyq6A2davIBBGSqLF2VeMtw7d-uxu8Oj6LOZ6lwWV0MYRWUK77nEGuQgQCAdtNZL1E7x-giErhxahzk8S1f6w1kf50nqk_brJfA6B1ci-Pla1z33JdVPoabtRTNHXdO11QqHehedWyd2MP-BxmgDcwFz63LC7nsZpDH4HJEQA626L2ybUMK2S8K2EFz9gtDlKzOXIC1waIw8eRpWWGVoQBfe6i1jCF3-6rm-e7guhbGhHq_-XtNB1iBr63jtJHdS1z6xDxjW49nwfJZcyZdgM5WjqyJ7vvjesu0VMdjuHTgBERj82XbDLNHgbzHsPdwLwrarC9RVo6SQTp2DonCD-TiAaQV_966BvglvUyYJYVua_Cdj_wda-C825bM9oV0DLByxRsMd5tGNQ5-1DmQB8tZl42N5TG5E9kJgdWsEgtA5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