Issue 126373
Summary Template class friend declaration of template class gets attached to module which instantiates it
Labels new issue
Assignees
Reporter es1024
    When I have a template class in the global module fragment with a template class friend, and the class is instantiated inside a module, the friend declaration of the class appears to get attached to the module. This results in an error if two such modules (or module fragments) do this and one imports the other.

Reproducer (on godbolt: https://godbolt.org/z/61hTx776G):
```cpp
// test.h
template<typename T>
struct Test {
  template<typename U>
  friend class Test;
};

// module1.cppm
module;
#include "test.h"
export module module1;
export void f1(Test<int>) {}

// module2.cppm
module;
#include "test.h"
export module module2;
import module1;
export void f2(Test<float>) {}
```
yields
```
In module 'module1' imported from /app/module2.cppm:4:
test.h:4:16: error: declaration 'Test' attached to named module 'module1' cannot be attached to other modules
    4 |   friend class Test;
      |                ^
test.h:2:8: note: also found
    2 | struct Test {
      |        ^
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to