<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/71484>71484</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [C++20][Modules] Name is not visible in instantiation of an imported function template
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          cpplearner
      </td>
    </tr>
</table>

<pre>
    `clang++ --version`:

```
clang version 17.0.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\LLVM-17.0.4\bin
```

mod1.cpp:

```c++
export module mod1;

export template<class T>
T mod1_f(T x) {
    return x;
}
```

mod2.cpp:

```c++
export module mod2;
import mod1;

export template<class U>
U mod2_g(U y) {
 return mod1_f(y);
}
```

mod3.cpp:

```c++
export module mod3;
import mod2;

export int mod3_h(int p) {
    return mod2_g(p);
}
```

`clang++ -std=c++20 -x c++-module -c -fprebuilt-module-path=. mod1.cpp -fmodule-output=mod1.pcm`
`clang++ -std=c++20 -x c++-module -c -fprebuilt-module-path=. mod2.cpp -fmodule-output=mod2.pcm`
`clang++ -std=c++20 -x c++-module -c -fprebuilt-module-path=. mod3.cpp -fmodule-output=mod3.pcm`:

```
In file included from mod3.cpp:2:
D:\test\test-module\mod2.cpp:6:12: error: call to function 'mod1_f' that is neither visible in the template definition nor found by argument-dependent lookup
    6 |     return mod1_f(y);
      |            ^
mod3.cpp:5:12: note: in instantiation of function template specialization 'mod2_g<int>' requested here
    5 | return mod2_g(p);
      | ^
D:\test\test-module\mod1.cpp:4:3: note: 'mod1_f' should be declared prior to the call site
    4 | T mod1_f(T x) {
      |   ^
1 error generated.
```

I think the name `mod1_f` should be visible within `mod2`, because `mod1` is imported there.

Adding `import mod1;` to `mod3` makes the error disappear, but IMO it shouldn't matter whether `mod3` imports `mod1`, since `mod1_f` is not directly referenced within `mod3`.
</pre>
<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