|
Boost Users : |
Subject: Re: [Boost-users] reference to '_1' is ambiguous
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-03-18 18:36:33
Eric Niebler:
> Peter Dimov wrote:
>> Eric Niebler:
>> ...
>>> namespace
>>> {
>>> // This reference should also be statically initialized
>>> placeholder<mpl::int_<1> > const & _1 =
>>> placeholder_instance<mpl::int_<1> >::value;
>>> }
>>
>> This is a problem for some precompiled header implementations.
>
> Huh.
Yep. Apparently, the unnamed namespace does not get an unique name in every
translation unit because of the precompilation.
>> Some compilers have fixed theirs to allow it, some have not, some only
>> allow(ed?) it when the variables are static.
>
> I notice I left "static" out of the example I sent around, but yes,
> placeholder_instance<>::value is supposed to be a class static.
This is not what I meant. On some compilers (going by the #ifdefs, MSVC and
Metrowerks), this:
namespace
{
X x;
}
doesn't work in a precompiled header, but this:
namespace
{
static X x;
}
does (because a static x doesn't cause a multiple definition link error.)
On Borland, neither works in a PCH. On g++ 4, both work but the second
causes an "unused variable" warning for every _K that is not referenced,
which is a bit annoying. I'm not sure what works on g++ 3, but it uses the
inline function path. :-)
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net