CWG Issue 8 (original) (raw)
This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 117a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.
2025-04-13
8. Access to template arguments used in a function return type and in the nested name specifier
Section: 11.8 [class.access]Status: CD1Submitter: Mike BallDate: unknown
[Moved to DR at 4/01 meeting.]
Consider the following example:
class A {
class A1{};
static void func(A1, int);
static void func(float, int);
static const int garbconst = 3;
public:
template < class T, int i, void (*f)(T, int) > class int_temp {};
template<> class int_temp<A1, 5, func> { void func1() };
friend int_temp<A1, 5, func>::func1();
int_temp<A1, 5, func>* func2();
}; A::int_temp<A::A1, A::garbconst + 2, &A::func>* A::func2() {...}
ISSUE 1:
In 11.8 [class.access] paragraph 5 we have:
All access controls in clause 11 affect the ability to access a class member name from a particular scope... In particular, access controls apply as usual to member names accessed as part of a function return type, even though it is not possible to determine the access privileges of that use without first parsing the rest of the function declarator. This means, if we take the loosest possible definition of "access from a particular scope", that we have to save and check later the following names
A::int_temp
A::A1
A::garbconst (part of an expression)
A::func (after overloading is done)
I suspect that member templates were not really considered when this was written, and that it might have been written rather differently if they had been. Note that access to the template arguments is only legal because the class has been declared a friend, which is probably not what most programmers would expect.
Rationale:
Not a defect. This behavior is as intended.
ISSUE 2:
Now consider void A::int_temp<A::A1, A::garbconst + 2, &A::func>::func1() {...} By my reading of 11.8.8 [class.access.nest] , the references toA::A1, A::garbconst and A::func are now illegal, and there is no way to define this function outside of the class. Is there any need to do anything about either of these Issues?
Proposed resolution (04/01):
The resolution for this issue is contained in the resolution for issue 45.