Issue 71484
Summary [C++20][Modules] Name is not visible in instantiation of an imported function template
Labels new issue
Assignees
Reporter cpplearner
    `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`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to