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?