stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Farid Zaripov" <>
Subject Re: svn commit: r627648 - in /stdcxx/trunk/include: ./ loc/ rw/
Date Fri, 22 Feb 2008 23:48:18 GMT
From: Martin Sebor []
Subject: Re: svn commit: r627648 - in /stdcxx/trunk/include: ./ loc/ rw/

> I'm not sure I understand the problem. Is it because we declare
> some explicit template instantiations when building the library
> as
>    extern template __declspec(dllexport) void foo<int>();
  Yes. Here the __declspec(dllexport) attribute leads to instantiating of the template class
or function,
but extern keyword tells to not instantiate, because the template will be instantiated in
the another module.
And the compiler doesn't know what to do: instantiate template in current module or not. I
see that MSVC
prefer __declspec(dllexport) and instantiates the template. So in example the classes string
and wstring
are instantiated in every .cpp file, where <string> is included. Actually this is my
assumption ans I don't
know exactly whether is true on not. But after this patch the size of the object files has
reduced (the size
of the resulting .dll in shared builds is not changed).

  From MSDN: 

Error Message

'<identifier>' : '__declspec(dllexport)' and 'extern' are incompatible on an explicit

The explicit template instantiation named <identifier> is modified by both the __declspec(dllexport)
and extern keywords. However, these keywords are mutually exclusive. The __declspec(dllexport)
keyword means instantiate the template class, while the extern keyword means do not automatically
instantiate the template class.

> Why does this happen, and doesn't the problem affect ordinary
> classes or functions as well? I.e., wouldn't either of the two
> declarations below be a problem?
>    extern __declspec(dllexport) void foo();
>    __declspec(dllexport) void foo();
  These declarations both are the same thing.

  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message