Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

we didn't explicitly specify that the current instantiation does not cause an implicit instantiation #5289

Open
xmh0511 opened this issue Feb 11, 2022 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Feb 11, 2022

[temp.inst] p16

There is an implementation-defined quantity that specifies the limit on the total depth of recursive instantiations ([implimits]), which could involve more than one template. The result of an infinite recursion in instantiation is undefined.

has an example that:

template<class T> class X {
  X<T>* p;    // #1      // OK
  X<T*> a;    // #2      // implicit generation of X<T> requires
                    // the implicit instantiation of X<T*> which requires
                    // the implicit instantiation of X<T**> which …

  // an extra example
  explicit(sizeof(X<T>)>1) operator int(){  // #3
      return 0;
  }
};

In either case of the three, the injected-class-name X is used as a template-name as per [temp.local] p1. That means, all the use of X can be replaced by ::X. [temp.inst] p2 states that

Unless a class template specialization is a declared specialization, the class template specialization is implicitly instantiated when the specialization is referenced in a context that requires a completely-defined object type or when the completeness of the class type affects the semantics of the program.

The operand of sizeof requires the operand to have a completely-defined object type and the class template specialization X<T> is not a declared specialization, thus, that operand should cause the implicit instantiation of X<T>, the implicit instantiation for X<T>, in turn, causes the implicit instantiation of explicit(sizeof(X<T>)>1) , which process is recursive.

We do not have a sufficient reason that can interpret why the current instantiation won't cause that non-reasonable instantiation that would violate [temp.inst] p16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant