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

            Bug ID: 122822
           Summary: [modules] Attachment of non-temploid friend
                    declarations
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nshead at gcc dot gnu.org
            Blocks: 103524
  Target Milestone: ---

Consider:

  // x.cpp
  export module X;
  export void x();

  // y.cpp
  import X;
  struct A {
    friend void x();
  };
  struct B {
    friend void ::x();
  };
  template <typename T> struct C {
    friend void x() {}
  };
  template struct C<int>;

These friend declarations should probably all be valid, and declare x@X.  This
doesn't seem to quite be the letter of the wording in the standard, but appears
to be the intention of CWG2588.

But implementing this will require reworking how we represent friend
declaration attachments.  Temploid friends are currently OK because we can use
'imported_temploid_friends' to give a side-channel expression saying that the
friend decl has the same attachment as the template it was declared in, but for
the declarations in 'A' and 'B' here, we lose the DECL_MODULE_IMPORT_P flag (as
we should, because the active declaration no longer came purely from an import)
but there's no longer a decl that we can tie our attachment to.

Perhaps the 'imported_temploid_friends' map should instead just become a map to
the module ID, and we don't follow it in 'get_originating_module_decl' anymore,
but rather also look up this decl in the map whenever we need to get the module
we're attached to if DECL_MODULE_IMPORT_P returns false.  Maybe even we add a
new flag about this, though that's probably not needed.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103524
[Bug 103524] [meta-bug] modules issue

Reply via email to