Boost logo

Boost :

From: Ian McCulloch (ianmcc_at_[hidden])
Date: 2004-05-07 18:06:45


David Abrahams wrote:

> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> writes:
>
>> "David Abrahams" <dave_at_[hidden]> wrote
>>
>>> Any time a template is instantitated, all names in its definition must
>>> map to the same entities in each translation unit, or you violate the
>>> ODR. By definition, names in the unnamed namespace refer to distinct
>>> entities in each translation unit.

But typedef only introduces aliases for an existing type. Does that qualify
for "map[s] onto the same entity" ?

>>
>> Does this mean that it's not allowed to use anonimous namespace-level
>> names inside templates?
>
> Unless those, too, are in the unnamed namespace, I think that's
> technically correct. You can probably get away with it, though.
>
>> I assume there also should be problems with non-template classes,
>> too, if anonimous namespace-defined names are used inside the body
>> of such a class...
>
> Yes, definitely.
>
>> OTOH, you said "all names in its definition". Does this also mean "all
>> names used to produce this definition"?
>
> I think so.
>
>> Because if we use "typeof" inside such template, it would still
>> resolve to the same type in different translation units (after all
>> the metaprogramming used to produce this type is done).
>
> I understand that. I think you can get away with it, but that it's
> not legal. This is another reason I think Boost.Bind's placeholders
> have to leave the unnamed namespace.
>
>> IOW, such templates in different translation units will be absolutely the
>> same, although in each translation unit the compiler will have to
>> instantiate different intermediate classes in order to produce them.

Those intermediate classes are in an unnamed namespace and not an ODR
violation in themselves?

>
> Right.
>
>> Do you still think this should be a problem?
>
> "_Should_ be?" no, I never did. I just think it's technically a
> violation of the rules.
>

If I understand correctly, you are saying that

// header.h
namespace {
  typedef int foo;
}

struct bar { foo f; };

// end header.h

causes an ODR violation if type bar (or even foo) is used in more than one
translation unit? Can you quote chapter and verse? (or perhaps that
should be asked on c.s.c++).

Cheers,
Ian McCulloch


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