This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/85943] New: Template function permits outside access to private variable


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

            Bug ID: 85943
           Summary: Template function permits outside access to private
                    variable
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: achuah at drwsg dot com
  Target Milestone: ---

This probably should be classified under meta-bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59002

See this example on Godbolt's compiler explorer: https://godbolt.org/g/skvWAt

If the accessing function were not a template function, then GCC correctly
prevents the private access.

If the private member was a function instead of a variable, then GCC correctly
prevents the private access, but only upon instantiation.

Note: in all of these cases, clang will not compile, regardless of whether
there's been an instantiation of the template.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]