Boost logo

Boost :

Subject: Re: [boost] SafeInt code proposal
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-23 16:01:50


Niels Dekker - address until 2010-10-10 wrote:
> Jean-Francois Bastien wrote:
>> [pedanticism]
>> Don't both your examples rely on pre-standard C++ friend declarations
>> and definitions injecting the function name in the innermost enclosing
>> namespace? I might be reading this worng, but [namespace.memdef]
>> paragraph 3 states: "The name of the friend is not found by unqualified
>> lookup (3.4.1) or by qualified lookup (3.4.3) until a matching
>> declaration is provided in that namespace scope".
>> So you'd still need to declare in the namespace. From what I understand
>> the examples shouldn't work.
>> Correct me if I'm wrong :)
> Well... I do appreciate your pedanticism, but I think you're wrong.
> All the compilers I tried accept the function calls to the inline
> friend function, operator-(safe_int,safe_int), including MSVC 2008
> SP1, Comeau (, and g++ 4.1.2, run at
> You might want to have a look at [temp.inject] ("Friend names declared
> within a class template"). Quoting the latest C++0x Working Draft,
>, 14.7.5/2
> (slightly reformatted):
> "As with non-template classes, the names of namespace-scope friend
> functions of a class template specialization are not visible during an
> ordinary lookup unless explicitly declared at namespace scope (11.4).
> Such names may be found under the rules for associated classes
> (3.4.2). [ Example: <snip> ]

Exactly. In the current standard, they can be found by
argument-dependent lookup:

When considering an associated namespace, the lookup is the same as the
lookup performed when the associated
namespace is used as a qualifier ( except that:
— Any using-directives in the associated namespace are ignored.
— Any namespace-scope friend functions declared in associated classes
are visible within their respective
namespaces even if they are not visible during an ordinary lookup (11.4).

In Christ,
Steven Watanabe

Boost list run by bdawes at, gregod at, cpdaniel at, john at