6

Given the following module

// mod.cpp
export module mod;

export template<typename T>
struct something
{
    constexpr something(T){}
};


export template<typename T>
constexpr auto make_something(T t)
{
    return something{t}; // uses CTAD
}

Compiled with clang: clang++ -std=c++20 -stdlib=libc++ -fmodules -c -Xclang -emit-module-interface -o mod.pcm mod.cpp

And the following application code:

import mod;

int main()
{
        constexpr auto x = make_something(7);
}

Compiled with: clang++ -std=c++20 -stdlib=libc++ -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=. main.cpp

The latter fails with the following error message:

In file included from main.cpp:1:
mod.cpp:13:12: error: no viable constructor or deduction guide for deduction of template arguments of 'something'
    return something{t}; // uses CTAD
           ^
main.cpp:5:28: note: in instantiation of function template specialization 'make_something<int>' requested here
        constexpr auto x = make_something(7);
                           ^
1 error generated.

Of course, I can change the module code and specify the the template parameter. However, I wonder:

Is this behavior expected for module code or a compiler bug?

Rumburak
  • 3,416
  • 16
  • 27
  • Skimming through the relevant standard parts I can't find anything that explicitly alters the behavior of CTAD in respect to modules. I think it's just a bug (the module support is still incomplete for all major compiler vendors after all), but I wasn't that thorough with my research. – Timo Mar 24 '20 at 09:52
  • Yes, compiler bug. – Barry Mar 24 '20 at 12:40
  • 1
    Thanks, [reported](https://bugs.llvm.org/show_bug.cgi?id=45292). – Rumburak Mar 24 '20 at 14:08

0 Answers0