This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 114a. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-04-18


2074. Type-dependence of local class of function template

Section: 13.8.3.2  [temp.dep.type]     Status: drafting     Submitter: Richard Smith     Date: 2015-01-20

According to 13.8.3.2 [temp.dep.type] paragraph 9, a local class in a function template is dependent if and only if it contains a subobject of a dependent type. However, given an example like

  template<typename T> void f() {
    struct X {
      typedef int type;
  #ifdef DEPENDENT
      T x;
  #endif
    };
  X::type y;    // #1
  }
  void g() { f<int>(); }

there is implementation variance in the treatment of #1, but whether or not DEPENDENT is defined appears to make no difference.

In a related question, should a value-dependent alignas specifier cause a type to be dependent? Given

  template<int N> struct Y { typedef int type; };
  template<int N> void h() {
    struct alignas(N) X {};
    Y<alignof(X)>::type z;   // #2
  }
  void i() { h<4>(); }

Most/all implementations issue an error for a missing typename in #2.

Perhaps the right answer is that the types should be dependent but a member of the current instantiation, permitting name lookup without typename.

Additional notes (September, 2022):

At present, the term "current instantiation" is defined for class templates only, and thus does not apply to function templates.

Moreover, the resolution for this issue should also handle local enums, with particular attention to 9.7.2 [enum.udecl] paragraph 1:

The elaborated-enum-specifier shall not name a dependent type and...

This rule, without amendment, would disallow the following reasonable example if local enums were made dependent types:

template <class T>
void f() {
  enum class E { e1, e2 };
  using enum E;
}