Boost logo

Boost :

From: Steve Clamage (Stephen.Clamage_at_[hidden])
Date: 2005-07-06 15:44:44


Slightly different and simplified example:

template<class U>
static void smart_cast_reference(U& u) {}

template <typename T>
void foo(int c)
{
   smart_cast_reference<int>(c);
}

Suppose (global) template foo is instantiated in more than one translation
unit. Since smart_cast_reference does not have external linkage, not all
instances of foo can refer to the same instance of smart_cast_reference<int>,
and the ODR is violated.

I'm pretty sure there is a name-lookup rule that makes this test case invalid,
but I haven't found it yet. (Still looking.)

---
Steve Clamage, stephen.clamage_at_[hidden]
Robert Ramey wrote:
> I have a sneaking feeling I might be a priniciple culprit here.
> 
> Steve Clamage wrote:
> 
>>You can't use a static template in a global template function because
>>it violates the One-Definition Rule, among possibly other rules.
> 
> 
> Could you expand upon this a little more?  I don't see the ODR violation or
> other rule violation.
> 
> 
>>I have found that other compilers accept this code, but reject it when
>>you put them in standard-conformning mode. (To see the rejection with
>>some compilers, you need to build the executable.)
> 
> 
>>How critical to BOOST is this style of coding? Could the static
>>templates be made global?
> 
> 
> Generally we aspire to make our code conform to the standard.  If its not,
> then we're interested in changing it so it is.  Having said that, It's often
> very difficult to figure out what the standard means.  Of course the fact
> that different compilers behave differently also makes it hard.
> 
> Of course if you want to make your compiler available to library writers at
> a reasonable cost (i.e. free) you might manage to shift some work on to us.
> 
> Robert Ramey

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