https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122098

            Bug ID: 122098
           Summary: Unexpected access error for private member function
                    template referenced from same class
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kab at acm dot org
  Target Milestone: ---

Created attachment 62471
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62471&action=edit
test code exhibiting the compile failure

Compiling the attached test file (with -std=c++14 through c++23) reports:

private-member-function-template-access.cpp: In function 'auto foo()':
private-member-function-template-access.cpp:27:16: error: 'static constexpr int
Impl::f() [with T = int]' is private within this context
   27 |   return Impl::XX<int>{};
      |                ^~~~~~~
private-member-function-template-access.cpp:14:15: note: declared private here
   14 | constexpr int Impl::f() {
      |               ^~~~

The member function template "f" is indeed private, but the reference to it is
in the same class that declares it, so should be accessible from there.

It's actually even weirder than that. The test file contains a couple more
cases that are commented out. One of them, involving an indirection to the
class triggering the warning via a type alias also in the class, does not warn.
 The other, involving a similar indirection through a type alias at global
scope, does warn.

This issue seems to have existed for a long time, and is still present on gcc
tip as of 2025-09-28.

This looks somewhat similar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97740
but that one was recently fixed, this one is still present.

Reply via email to