Skip to content

CWG3099 [temp.inst] Instantiation of type aliases from alias templates unspecified #782

Description

@hubert-reinterpretcast

Full name of submitter (unless configured in github; will be published with the issue): Hubert Tong

Reference (section label): [temp.alias], [temp.inst]

Link to reflector thread (if any): N/A

Issue description:

P2996 added the idea that a type alias can result from instantiation of an alias template; however, the timing of the instantiation (and its relation to the immediate context) is unspecified.

Some thoughts:

  • The "traditional" expansion of alias templates are in the immediate context, but the instantiation of class and function templates are not.
  • Unlike classes and functions, it is not possible to declare a type alias without defining it (which may motivate "immediate" instantiation; which, in turn, reduces friction for an "immediate context" treatment).

Consider https://godbolt.org/z/Wof7fcr3a:

#include <meta>

using namespace std::meta;

template <typename T> using A = T *;

template <auto> struct Sink;

template <typename T> void f(Sink<^^A<T> > * = 0); // immediately instantiated and considered as part of the immediate context?
template <typename T> void f(int = 0);
void g() { f<int &>(); }

constexpr auto x = substitute(^^A, {^^int &});  // valid until dealias?

Observations:

  • Implementations are performing the instantiation even when the specialization is merely named for the purposes of producing a reflection (which, in theory, only requires the identity and not the instantiation of the specialization). This extends to the case where substitute is used to form the specialization.
  • Implementations are treating the formation of the pointer-to-reference as being in the immediate context, which does not match the class/function template instantiation model.

Suggested resolution:

Gather input from P2996 paper authors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions