Title
Access and alias templates
Status
drafting
Section
13.7.8 [temp.alias]
Submitter
Jason Merrill

Created on 2012-09-17.00:00:00 last changed 87 months ago

Messages

Date: 2016-02-15.00:00:00

Notes from the February, 2016 meeting:

CWG reaffirmed the direction described in the October, 2012 note above. With regard to the November, 2014 note regarding granting of friendship, it was observed that the same problem occurs with enumerators, which might refer to inaccessible names in the enumerator volue. The solution in both cases is to embed the declaration in a class and grant the class friendship. See issue 1844, dealing with the definition of “immediate context.”

Date: 2016-02-15.00:00:00

Additional note, November, 2014:

Concern has been expressed that the intent to analyze access in the context of the alias template definition is at odds with the fact that friendship cannot be granted to alias templates; if it could, the access violation in the original example could be avoided by making foo a friend of class B, but that is not possible.

Additional node, February, 2016:

The issue has been returned to "open" status to facilitate further discussion by CWG as to whether the direction in the October, 2012 note is still desirable.

Date: 2014-02-15.00:00:00

Additional note (February, 2014):

A related problem is raised by the definition of std::enable_if_t (21.3.3 [meta.type.synop]):

  template <bool b, class T = void>
  using enable_if_t = typename enable_if<b,T>::type;

If b is false, there will be no type member. The intent is that such a substitution failure is to be considered as being “in the immediate context” where the alias template specialization is used, but the existing wording does not seem to accomplish that goal.

Date: 2012-10-15.00:00:00

Notes from the October, 2012 meeting:

The consensus of CWG was that instantiation (lookup and access) for alias templates should be as for other templates, in the definition context rather than in the context where they are used. They should still be expanded immediately, however.

Date: 2012-09-17.00:00:00

The interaction of alias templates and access control is not clear from the current wording of 13.7.8 [temp.alias]. For example:

  template <class T> using foo = typename T::foo;

  class B {
    typedef int foo;
    friend struct C;
  };

  struct C {
    foo<B> f;    // Well-formed?
  };

Is the substitution of B::foo for foo<B> done in the context of the befriended class C, making the reference well-formed, or is the access determined independently of the context in which the alias template specialization appears?

If the answer to this question is that the access is determined independently from the context, care must be taken to ensure that an access failure is still considered to be “in the immediate context of the function type” (13.10.3 [temp.deduct] paragraph 8) so that it results in a deduction failure rather than a hard error.

History
Date User Action Args
2017-02-06 00:00:00adminsetmessages: + msg5758
2017-02-06 00:00:00adminsetstatus: open -> drafting
2016-02-15 00:00:00adminsetstatus: drafting -> open
2014-11-24 00:00:00adminsetmessages: + msg5223
2014-03-03 00:00:00adminsetmessages: + msg4894
2012-11-03 00:00:00adminsetmessages: + msg4106
2012-11-03 00:00:00adminsetstatus: open -> drafting
2012-09-17 00:00:00admincreate