This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2024-11-11
[Voted into WP at March 2004 meeting.]
The example in _N4868_.13.8.6 [temp.inject] paragraph 2 is incorrect:
template<typename T> class number { number(int); //... friend number gcd(number& x, number& y) { /* ... */ } //... }; void g() { number<double> a(3), b(4); //... a = gcd(a,b); // finds gcd because number<double> is an // associated class, making gcd visible // in its namespace (global scope) b = gcd(3,4); // ill-formed; gcd is not visible }
Regardless of the last statement ("b = gcd(3,4);"), the above code is ill-formed:
a) number's constructor is private;
b) the definition of (non-void) friend 'gcd' function does not contain a return statement.
Proposed resolution (April 2003):
Replace the example in _N4868_.13.8.6 [temp.inject] paragraph 2
bytemplate<typename T> class number { number(int); //... friend number gcd(number& x, number& y) { /* ... */ } //... }; void g() { number<double> a(3), b(4); //... a = gcd(a,b); // finds gcd because number<double> is an // associated class, making gcd visible // in its namespace (global scope) b = gcd(3,4); // ill-formed; gcd is not visible }
template<typename T> class number { public: number(int); //... friend number gcd(number x, number y) { return 0; } private: //... }; void g() { number<double> a(3), b(4); //... a = gcd(a,b); // finds gcd because number<double> is an // associated class, making gcd visible // in its namespace (global scope) b = gcd(3,4); // ill-formed; gcd is not visible }
Drafting note: Added "return" to the friend function, removed references in gcd arguments, added access specifiers.