[llvm-bugs] [Bug 41895] New: [clang-cl] __declspec(dllexport) on class declaration implicitly instantiates templates

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 16 01:49:39 PDT 2019


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

            Bug ID: 41895
           Summary: [clang-cl] __declspec(dllexport) on class declaration
                    implicitly instantiates templates
           Product: clang
           Version: 7.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Driver
          Assignee: unassignedclangbugs at nondot.org
          Reporter: me at mark-ingram.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

Created attachment 21952
  --> https://bugs.llvm.org/attachment.cgi?id=21952&action=edit
Test file

Attempting to export a class declaration that will be partially specialised
results in an error:

template<typename T>
class __declspec(dllexport) Foo
{
public:
        static const int Bar;
};

template<> const int Foo<char>::Bar = 42;

Using clang-cl:

$ clang-cl -c test.cpp
test.cpp(8,33):  error: explicit specialization of 'Bar' after instantiation
template<> const int Foo<char>::Bar = 42;
                                ^
test.cpp(5,19):  note: implicit instantiation first required here
        static const int Bar;
                         ^
1 error generated.

Using cl:
> cl /c test.cpp /nologo
test.cpp



The work around that I have is to export individual class members, which
prevents the implicit template instantiation, and allows a subsequent partial
template specialisation.

Also, the diagnostic isn't quite right, because the implicit instantiation
happens when the class is exported, not when the member is defined (removing
the __declspec(dllexport) allows the code to compile with clang-cl).

-- 
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/20190516/0eebf316/attachment-0001.html>


More information about the llvm-bugs mailing list