Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-11-07 13:45:59


Joel de Guzman <joel_at_[hidden]> writes:

> Any links to the thread?

No, we've been doing this offline. I'll try to forward something to
you.

>> 1. The placeholders are statically initialized const POD objects in
>> an unnamed namespace and you have likely ODR violation when used
>> by templates in multiple translation units.
>> 2. The placeholders are dynamically initialized references in an
>> unnamed namespace and you risk undefined behavior when they are
>> used without initialization due to initialization order issues
>> 3. The placeholders are dynamically initialized objects in an
>> unnamed
>> namespace, and you have likely ODR violation *and* initialization
>> order issues
>> Seems from the doc like you have #3, which is the worst of both
>> worlds. No?
>
> Actually it is 4:
>
> 4. The placeholders are dynamically initialized *const* objects in
> namespace phoenix

That's essentially 1, in that you get a different object in each TU
and are likely to end up with an ODR violation.

> Well, we can easilly make them PODs, so:
>
> 5. The placeholders are statically initialized *const* POD objects
> in namespace phoenix

Same problem.

> So, question: how does this code below constitute ODR violation?
>
> namespace x // named
> {
> T const pod = T(); // T is a POD
> }

It does not. You need two translation units and a template,
instantiated in each one, that uses your object "pod."

> is this link relevant?:
> http://lists.boost.org/Archives/boost/2004/06/67159.php

Precisely.

> how about:
> http://lists.boost.org/Archives/boost/2001/05/12609.php

I don't think so. Internal linkage doesn't save you from an ODR
violation.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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