cpp-member-accessor
cpp-member-accessor copied to clipboard
Template methods doesn't work on Clang
Using template methods doesn't work for the latest and past few versions of the Clang compiler.
Tested on Godbolt with Clang 11.0.0 -> Live code
Error:
x86-64 clang 11.0.0
-std=c++20 -O3
1
<Compilation failed>
x86-64 clang 11.0.0 - cached
<source>:106:55: error: 'max' is a private member of 'Test'
template class accessor::MakeProxy<TestMaxInt, &Test::max>;
~~~~~~^~~
<source>:87:5: note: implicitly declared private here
T max(T& lhs, T& rhs) { return (lhs > rhs) ? lhs : rhs; }
^
<source>:107:57: error: 'max' is a private member of 'Test'
template class accessor::MakeProxy<TestMaxFloat, &Test::max>;
~~~~~~^~~
<source>:87:5: note: implicitly declared private here
T max(T& lhs, T& rhs) { return (lhs > rhs) ? lhs : rhs; }
^
<source>:108:60: error: 'max' is a private member of 'Test'
template class accessor::MakeProxy<TestMax<double>, &Test::max>;
~~~~~~^~~
<source>:87:5: note: implicitly declared private here
T max(T& lhs, T& rhs) { return (lhs > rhs) ? lhs : rhs; }
^
3 errors generated.
ASM generation compiler returned: 1
<source>:106:55: error: 'max' is a private member of 'Test'
template class accessor::MakeProxy<TestMaxInt, &Test::max>;
~~~~~~^~~
<source>:87:5: note: implicitly declared private here
T max(T& lhs, T& rhs) { return (lhs > rhs) ? lhs : rhs; }
^
<source>:107:57: error: 'max' is a private member of 'Test'
template class accessor::MakeProxy<TestMaxFloat, &Test::max>;
~~~~~~^~~
<source>:87:5: note: implicitly declared private here
T max(T& lhs, T& rhs) { return (lhs > rhs) ? lhs : rhs; }
^
<source>:108:60: error: 'max' is a private member of 'Test'
template class accessor::MakeProxy<TestMax<double>, &Test::max>;
~~~~~~^~~
<source>:87:5: note: implicitly declared private here
T max(T& lhs, T& rhs) { return (lhs > rhs) ? lhs : rhs; }
Neither it works in clang 13.
https://github.com/martong/access_private works.
@KOLANICH I wasn't aware of this library. Thanks for sharing, I will check it!
Interestingly, the above example works in clang 14 and above @ godbolt