Skip to content

[P0692R1] Access checking not waived for declarations of explicit specializations of function and variable templates #51111

@dfrib

Description

@dfrib
mannequin
Bugzilla Link 51769
Version trunk
OS Linux
CC @zygoloid

Extended Description

[temp.spec]/6[1] was added to the C++20 spec by implementation of P0692R1[2]:

"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."

Meaning that programs (A) through (C) below are (arguably) well-formed:

(A) (DEMO: https://wandbox.org/permlink/P2GpDGy6mxMydtii)

class A { class B {}; };

template struct S {};
template<> struct S<A::B> {};

int main() {}

(B) (DEMO: https://wandbox.org/permlink/CZFZlMwC3VMzSBky):

class A { class B {}; };

template void foo() {};
template<> void foo<A::B>() {}

int main() {}

(C) (DEMO: https://wandbox.org/permlink/LX3LWSesx2tBCbMh)

class A { class B {}; };

template
constexpr bool v = false;

template<>
constexpr bool v<A::B> = true;

int main() {}

Moreover, program (D) below:

(D) (DEMO: https://wandbox.org/permlink/hjEw0n4UN0wQ55Fv)

class A { class B {}; };

template<typename T, typename U> struct S {};
template struct S<A::B, U> {};
template struct S<T, A::B> {};

int main() {}

is also (arguably) well-formed as per [temp.class.spec]/10[3], which covers waiving of access checking for template arguments in the simple-template-id of partial specializations, a paragraph that was also added as part of P0692R1.

However whilst Clang accepts (A), it rejects (B) through (D).

As per [4], the implementation status of P0692R1 is "partial" (so this may actually not be a bug report but an enhancement request).


[1] https://timsong-cpp.github.io/cppwp/n4861/temp.spec#6

[2] P0692R1 - Access Checking on Specializations
http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0692r1.html)

[3] https://timsong-cpp.github.io/cppwp/n4861/temp.class.spec#10

[4] https://clang.llvm.org/cxx_status.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions