Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c++ modules: uninstantiated template friend class [PR104234]
Here we're not clearing DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P for the instantiated/injected template friend class B, which confuses a later call to get_originating_module_decl for B. This patch fixes this by clearing the flag in tsubst_friend_class (as is already done for template friend functions by r11-5730-gf7aeb823d9b0de). After fixing that, we still fail to compile the testcase, rejecting the later definition of B with friend-6_a.C:10:26: error: cannot declare ‘struct B<T>’ in a different module ultimately because DECL_MODULE_ATTACH_P wasn't set on the original (injected) declaration of B. This patch fixes this by calling set_originating_module in tsubst_friend_class, but for that to work it seems we need to relax the assert in this latter function since get_originating_module_decl when called on the TYPE_DECL for B returns the corresponding TEMPLATE_DECL. (Alternatively we can instead call set_originating_module on the TYPE_DECL B as soon as it's created in lookup_template_class (which is what pushtag does), which doesn't need this assert change because at this point the TYPE_DECL doesn't have any TEMPLATE_INFO so get_originating_module_decl becomes a no-op. Would that be preferable?) Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/104234 gcc/cp/ChangeLog: * module.cc (set_originating_module): Document default argument. Relax assert to look through DECL_TEMPLATE_RESULT in the result of get_originating_module_decl. * pt.cc (tsubst_friend_class): Clear DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P and call set_originating_module on the instantiated template friend class. gcc/testsuite/ChangeLog: * g++.dg/modules/friend-6_a.C: New test.
- Loading branch information