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

            Bug ID: 120023
           Summary: When using c++ modules, put deduction guide in a
                    separate module unit file, the deduction will be
                    ignored
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kptas at proton dot me
  Target Milestone: ---

Compiler: latest gcc 16.0 built from git.

When using c++ modules, put primary template in a module unit file, and put
deduction guide in another separate module unit file, the deduction guide will
be dismissed. Otherwise, put primary template and deduction guide in the same
module unit file, compile OK.

p.cpp
```
export module pm.p;

export namespace pm
{
        template <typename>
        class my_class;
}
```

deduction.cpp
```
export module pm.deduction;

import pm.p;

export namespace pm
{
        my_class(const int &) -> pm::my_class<int>;
        my_class(const float &) -> pm::my_class<float>;
}
```

s1.cpp
```
export module pm.s1;

import pm.p;

export namespace pm
{
        template <>
        class my_class<int>
        {
        public:
                my_class(const int &) {}
                my_class(const float &) {}
        };
}
```

s2.cpp
```
export module pm.s2;

import pm.p;

export namespace pm
{
        template <>
        class my_class<float>
        {
        public:
                my_class(const int &) {}
                my_class(const float &) {}
        };
}
```

all.cpp
```
export module pm;

export import pm.p;
export import pm.deduction;
export import pm.s1;
export import pm.s2;
```

main.cpp
```
import pm;

int main()
{
        pm::my_class<int> a1{3.5f};
        pm::my_class<float> a2{7};
        pm::my_class a3{2.5f}; // This line cause error, because the deduction
guide is dismissed.
}
```

Compile:
g++ -fmodules-ts -std=c++26 p.cpp deduction.cpp s1.cpp s2.cpp all.cpp main.cpp
-o main

Reply via email to