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: unassignedclangb...@nondot.org
          Reporter: m...@mark-ingram.com
                CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to