Title
Access to template arguments used in a function return type and in the nested name specifier
Status
cd1
Section
11.8 [class.access]
Submitter
Mike Ball

Created on 1998-10-24.00:00:00 last changed 162 months ago

Messages

Date: 2001-04-15.00:00:00

[Moved to DR at 4/01 meeting.]

Date: 2000-10-15.00:00:00

Proposed resolution (04/01):

The resolution for this issue is contained in the resolution for issue 45.

Date: 2004-09-10.00:00:00

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 to A::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?

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2003-04-25 00:00:00adminsetstatus: dr -> wp
2002-05-10 00:00:00adminsetmessages: + msg677
2001-05-20 00:00:00adminsetstatus: ready -> dr
2000-11-18 00:00:00adminsetmessages: + msg399
2000-11-18 00:00:00adminsetstatus: open -> ready
1998-10-24 00:00:00admincreate