Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-13 22:03:23


"Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:

>> Arkadiy Vertleyb wrote:
>> > "Thorsten Ottosen" <thorsten.ottosen_at_[hidden]> wrote
>> >
>> >
>> >>>>42 usages of unnamed namespaces in headers (including .ipp files)
>> >>>
>> >>>
>> >>>>bind (1)
>> >>>
>> >>>
>> >>>I'm not sure what I'm expected to do about that one. Bind has been
> using
>> >>>an
>> >>>unnamed namespace for its placeholders for quite a while now.
>> >>
>> >>What is the problem with an unnamed namespace in a header anyway? Is it
>> >>illegal according to the standard?
>> >
>> >
>> > ODR is potentially violated :-(
>> >
>>
>> How?
>
> Suppose you have a class A defined inside unnamed namespace (in a header).
> Suppose you also have a class B defined in terms of class A, but not inside
> unnamed namespace (in the same or another header).
>
> Now, if two translation units use the class B, the same class (B) is defined
> differently in these translation units (since unnamed namespaces are
> different and so B uses different A).
>
> Typeof has a specific test causing this condition. So far no compilers
> complained.

The difference is that in the case of Typeof, the ODR violation is
buried inside the library implementation. The library developers can
keep it hidden from users and are aware of the possible dangers. In
the case of bind, we're (almost) ensuring that its users will create
their own ODR violations, and we don't tell them there's any danger.
That's a bigger concern to me, for some reason.

-- 
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