Access control in template parameters

前端 未结 1 1074
野性不改
野性不改 2021-02-01 20:41

Inspired from this answer, which claims to subvert the access control system, I wrote the following minimal version of the hack

template
inline         


        
相关标签:
1条回答
  • 2021-02-01 21:43

    From [temp.spec]/6 (emphasis mine):

    The usual access checking rules do not apply to names in a declaration of an explicit instantiation or explicit specialization, with the exception of names appearing in a function body, default argument, base-clause, member-specification, enumerator-list, or static data member or variable template initializer. [ Note: In particular, the template arguments and names used in the function declarator (including parameter types, return types and exception specifications) may be private types or objects that would normally not be accessible. — end note  ]

    So this technique you see abuses this rule, which is primarely there to allow implementers of a class specialize templates (such as traits) with private types or other private entities

    0 讨论(0)
提交回复
热议问题