|
Boost : |
Subject: Re: [boost] [algorithm][hex] function hex_char_to_int in unnamed namespace in header file
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-12-03 15:10:58
On December 3, 2012 11:58:54 PM Marshall Clow <mclow.lists_at_[hidden]> wrote:
> On Dec 3, 2012, at 9:43 AM, Felipe Magno de Almeida
> <felipe.m.almeida_at_[hidden]> wrote:
>
> >
> http://boost.2283326.n4.nabble.com/Boost-inspection-notification-2007-06-09-RC-1-34-0-X-tt2628426.html#a2628478
> >
> > AFAIK, an unnamed namespace creates different entities for each
> > translation on which it is defined (by #inclusion,
> > for example).
>
> Yes.
>
> > If any entity defined in a unnamed namespace is used in
> > an external linkage definition, such as a
> > inline function or a template definition and this definition is used
> > in multiple TUs it causes ODR violations, because
> > it is defined differently (uses different entities) in each TU.
>
> And No. Because the call to it (in each TU) will call the entity in the
> specific unnamed namespace that was part of that translation unit.
Exactly, and that's what makes ODR violated. Imagine an inline function
in a header, the function depends on the entity in an unnamed
namespace. The function will be defined differently in each TU that
includes the header, and that's UB.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk