Boost logo

Boost :

Subject: Re: [boost] [testing] Add a tester with hidden visibility
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2015-05-07 12:39:55


On Thursday 07 May 2015 17:32:13 Niall Douglas wrote:
> On 7 May 2015 at 18:59, Andrey Semashev wrote:
> > > I have no idea why you continue to insist on trying to second guess
> > > the very well established pattern here. The design of the GCC
> > > visibility support was chosen back in 2004 to correctly support all
> > > combinations of GCC, MSVC and Mingw without any special casing,
> > > trickery, or any macro work above the traditional preprocessor logic
> > > used for MSVC.
> >
> > Well, it's not that simple. For example, if you dllexport a class template
> > and explicitly instantiate it in a dll with a non-exported type as a
> > template parameter, you will get what you want - an exported
> > specialization. Hidden visibility, OTOH, is viral, so the instantiated
> > template will silently become hidden in this case.
> >
> > Other than that, yes, it's rather similar to MSVC.
>
> It is a bad idea to dllexport templates as it greatly increases the
> chance of an ODR violation biting you in the ass (e.g. two internal
> private types with the same name). Nor is it ever necessary, as
> template implementation is always header only. Just leave templates,
> or any header implemented code, alone. Let them be compiled into a
> local implementation for every ELF object. Remove anything you really
> need to have exactly a single implementation of into a non-templated
> base class which is dllexported.

That's a very simplistic approach. In practice it is often needed to export a
template specialization for different reasons: dependency hiding, compilation
speedup, code size reduction, etc. Of course, there are complications and
caveats but "just don't do it" is often not an answer.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk