[llvm-bugs] [Bug 45292] New: Class template argument deduction (CTAD) not working in module

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 24 07:09:59 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45292

            Bug ID: 45292
           Summary: Class template argument deduction (CTAD) not working
                    in module
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rbock at eudoxos.de
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Given the following module

// ----------------------------------
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.
But this seems to be a bug, see also discussion here: 
https://stackoverflow.com/questions/60827958/should-class-template-argument-deduction-ctad-work-inside-modules

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200324/034783a9/attachment.html>


More information about the llvm-bugs mailing list