Skip to content

Modules: reachable template class is deemed incomplete at the point of instantiation if defined in a different partition #164466

@PiliLatiesa

Description

@PiliLatiesa

p1.cpp

export module m:p1;

template<typename>
class Incognita;

export template<typename T>
class Variable
{
public:
  Incognita<T> foo() const { return {*this}; }
};

p2.cpp

export module m:p2;

import :p1;

template<typename T>
class Incognita
{
public:
  Incognita(const Variable<T> &) {}
};

m.cpp

export module m;

export import :p1;
export import :p2;

example.cpp

import m;

int main()
{
Variable<double> x;

auto bar = x.foo();
}
example.cpp:7:14: error: implicit instantiation of undefined template 'Incognita<double>'
    7 | auto bar = x.foo();
      |              ^
p1.cpp:4:7: note: template is declared here
    4 | class Incognita;
      |       ^
p1.cpp:11:16: error: implicit instantiation of undefined template 'Incognita<double>'
   11 |   Incognita<T> foo() const { return {*this}; }
      |                ^
example.cpp:7:14: note: in instantiation of member function 'Variable<double>::foo' requested here
    7 | auto bar = x.foo();
      |              ^
p1.cpp:4:7: note: template is declared here
    4 | class Incognita;
      |       ^
p1.cpp:11:37: error: implicit instantiation of undefined template 'Incognita<double>'
   11 |   Incognita<T> foo() const { return {*this}; }
      |                                     ^
p1.cpp:4:7: note: template is declared here
    4 | class Incognita;
      |       ^

https://godbolt.org/z/naq543aqW

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions