c++: Avoid access check for dependent lookup results [PR124983]
C++ template lookup now correctly skips access checks on dependent scope members.
GCC’s template parsing has been improved to avoid performing access checks on members found within dependent scopes during dependent lookup. Previously, the strip_using_decl transformation could convert a USING_DECL to a TYPE_DECL, leading lookup_member to incorrectly attempt an access check on a dependent type. This commit modifies lookup_member to skip access checks when the lookup result originates from a dependent scope, aligning with template instantiation rules and fixing PR124983.
In Details
In GCC's C++ frontend, when resolving template names, lookup_member is called to find members. If strip_using_decl transforms a USING_DECL into a TYPE_DECL within a dependent context, lookup_member might incorrectly attempt to perform an access check. Access checks on dependent types must be deferred until instantiation time, as visibility can change based on template arguments. The enforce_access function asserts this invariant, causing an ICE. This commit modifies lookup_member to unconditionally skip access checks if the found declaration pertains to a member of a dependent s…
- dependent scope
- A scope within a C++ template that depends on template parameters. Its exact contents are not known until the template is instantiated.
- lookup_member
- A GCC internal function responsible for searching for members (variables, functions, types) within a class or struct.
- USING_DECL
- An internal GCC representation for a 'using declaration' in C++, which brings names from one scope into another.
- TYPE_DECL
- An internal GCC representation for a type declaration (e.g., class, struct, enum).
- access check
- In C++, verifying if a member (like private or protected data) is accessible from the current scope.
- template instantiation
- The process by which the compiler generates a specific version of a C++ template based on the template arguments provided.