- Kriang Lerdsuwanakij
- This is the approach I planned for [gccbug:16617] bugfix. The idea is to keep a list of things that require access check when parsing template declarations. And during template instantiation we run through this list and perform access checking. Currently we need to keep tree representation as SCOPE_REF for such purpose. For non-dependent TYPENAME_TYPE and UNBOUND_CLASS_TEMPLATE, they are always folded into the result *_TYPE and TEMPLATE_DECL so access checking are never performed on such cases [gccbug:16617]. The approach would be modifying a bunch of functions inside cp/semantics.c (perform_or_defer_access_check, perform_deferred_access_checks, etc.) Since those are the only functions that call enforce_access. Instead of just calling enforce_access, the logic will become
if inside template declaration push access check into some appropriate list else call enforce_access
- However there are some tricky issues:
- We now need current_var_decl. For example, a member function of a
- class template, a static member data of a class template, or the whole class template may be explicitly instantiated. So the logic to decide which list to push depends on current_function_decl, current_class_type, and the new current_var_decl. [Solved]
- We need to store file name and line number. So during template
- instantiation, we can point the user to the original location in the error message. A TREE_LIST doesn't have these, so we need to invent a new structure. The gengtype GTY marking for GC could get nasty in places like cp_parser_nested_name_specifier_opt since we need to save this structure around inside a 'cp_token'. [Solved]
- Some garbage collection problem I haven't spent time to look at yet.
- Keeping TREE_BINFO (that is still dependent) in a list cause segfault in some random place inside the compiler. [Solved]
- Duplicate diagnostic message need to be prevented. [Solved]
- Updated 28-5-05: An issue about default template argument and default function argument handling surfaces. This needs some tweaks to the overall design. So consider the work suspended until a nice solution is found. Earlier work on this project can be found below. Patch was planed to consist of 5 parts with 4 parts already posted.
- Part 5: Defer access check for template header