[llvm-bugs] [Bug 51769] New: [P0692R1] Access checking not waived for declarations of explicit specializations of function and variable templates

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 6 08:25:06 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51769

            Bug ID: 51769
           Summary: [P0692R1] Access checking not waived for declarations
                    of explicit specializations of function and variable
                    templates
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: invalid-bug
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: davveston at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

[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<typename T> struct S {};
 template<> struct S<A::B> {};

 int main() {}


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

 class A { class B {}; };

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

 int main() {}


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

 class A { class B {}; };

 template<typename T>
 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<typename U> struct S<A::B, U> {};
 template<typename T> 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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210906/80b7d833/attachment.html>


More information about the llvm-bugs mailing list