cpp-member-accessor icon indicating copy to clipboard operation
cpp-member-accessor copied to clipboard

Template methods doesn't work on Clang

Open hliberacki opened this issue 4 years ago • 3 comments

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; }

hliberacki avatar Jan 11 '21 23:01 hliberacki

Neither it works in clang 13.

https://github.com/martong/access_private works.

KOLANICH avatar Aug 18 '21 21:08 KOLANICH

@KOLANICH I wasn't aware of this library. Thanks for sharing, I will check it!

hliberacki avatar Aug 26 '21 08:08 hliberacki

Interestingly, the above example works in clang 14 and above @ godbolt

TedLyngmo avatar Feb 21 '23 16:02 TedLyngmo