[llvm-bugs] [Bug 40256] New: Dllexport on template instantiations has no effect in MinGW mode

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 8 14:12:07 PST 2019


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

            Bug ID: 40256
           Summary: Dllexport on template instantiations has no effect in
                    MinGW mode
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: martin at martin.st
                CC: blitzrakete at gmail.com, compnerd at compnerd.org,
                    david.majnemer at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk, rnk at google.com,
                    smeenai at fb.com

The following code snippet instantiates a template and dllexports the generated
symbols, when built in MSVC mode:


template<class T> class MyClass {
public:
  MyClass(int a);

private:  
  T val;
};  

template<class T> MyClass<T>::MyClass(int a) {
  val = a;
}

extern template class MyClass<int>;

template class __declspec(dllexport) MyClass<int>;


When built in MinGW mode, it doesn't produce any export directives, but it
doesn't when built with GCC either, and GCC warns:

dllexport.cpp:15:38: warning: type attributes ignored after type is already
defined [-Wattributes]
 template class __declspec(dllexport) MyClass<int>;

GCC does, however, produce export directives if the dllexport attribute is on
the template instantiation declaration:

extern template class __declspec(dllexport) MyClass<int>;
template class MyClass<int>;

The same also works when specified on the original template declaration. Clang
in MinGW mode, however, doesn't take the dllexport attribute into account in
any of the variants, and never produces export directives for the template
instantiation.

-- 
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/20190108/fba23bf3/attachment.html>


More information about the llvm-bugs mailing list