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

            Bug ID: 116403
           Summary: [modules] Deduction guides not reachable across
                    transitive non-exported imports
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          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:

  // a.cpp
  export module A;
  export template <typename T> struct S { S(int); };
  S(int) -> S<double>;

  // b.cpp
  export module B;
  import A;
  export using ::S;

  // c.cpp
  import B;
  int main() {
    S s(123);  // should be S<double>
  }

This should compile successfully, as deduction guides are always visible if
reachable, and reachability doesn't care that we didn't 'export import A' from
module B.

Instead we get:

$ g++ -fmodules-ts -S [abc].cpp
c.cpp: In function ‘int main()’:
c.cpp:4:10: error: class template argument deduction failed:
    4 |   S s(123);
      |          ^
c.cpp:4:10: error: no matching function for call to ‘S@A(int)’
In module A, imported at b.cpp:2,
of module B, imported at c.cpp:1:
a.cpp:2:41: note: candidate: ‘template<class T> S@A(int) -> S@A<T>’
    2 | export template <typename T> struct S { S(int); };
      |                                         ^
a.cpp:2:41: note:   template argument deduction/substitution failed:
c.cpp:4:10: note:   couldn’t deduce template parameter ‘T’
    4 |   S s(123);
      |          ^
In module A, imported at b.cpp:2,
of module B, imported at c.cpp:1:
a.cpp:2:37: note: candidate: ‘template<class T> S@A(S@A<T>) -> S@A<T>’
    2 | export template <typename T> struct S { S(int); };
      |                                     ^
a.cpp:2:37: note:   template argument deduction/substitution failed:
c.cpp:4:10: note:   mismatched types ‘S@A<T>’ and ‘int’
    4 |   S s(123);
      |          ^

It looks like my original 'hack' solution to just always consider deduction
guides exported is insufficient, and we'll need a more general name lookup
solution.


Referenced Bugs:

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

Reply via email to