Skip to content

accepts-invalid accessing private member of C++ class from scope specifier #134959

Open
@efriedma-quic

Description

@efriedma-quic
template<int x> class A { static const int xx = 3; template<int y> class B; };
template<int x> template<int y> class A<x>::B { };
template<typename T> T f();
template<> int A<1>::B<A<1>::xx>::* f(){return nullptr;}

clang accepts.

gcc produces:

<source>: In function 'T f() [with T = int A<1>::B<3>::*]':
<source>:4:22: error: 'template<int y> class A<1>::B' is private within this context
    4 | template<> int A<1>::B<A<1>::xx>::* f(){return nullptr;}
      |                      ^
<source>:1:74: note: declared private here
    1 | template<int x> class A { static const int xx = 3; template<int y> class B; };
      |                                                                          ^
<source>:4:30: error: 'const int A<1>::xx' is private within this context
    4 | template<> int A<1>::B<A<1>::xx>::* f(){return nullptr;}
      |                              ^~
<source>:1:44: note: declared private here
    1 | template<int x> class A { static const int xx = 3; template<int y> class B; };
      |                                            ^~

I think clang is accidentally suppressing the access checks while disambiguating between a template function and a template member.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions