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

[temp.expl.spec] p6 explicitly specialized class vs explicitly specialized class template #4846

Open
xmh0511 opened this issue Aug 29, 2021 · 5 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Aug 29, 2021

A member of an explicitly specialized class is not implicitly instantiated from the member declaration of the class template

Isn't that the same things are also for an explicitly specialized class template? I also think explicitly specialized class and explicitly specialized class templates are different according to the context of [temp.expl.spec]. I think the first sentence should be that

A member of an explicitly specialized class or class template is not implicitly instantiated from the member declaration of the templated class; instead, the member of the class template specialization shall itself be explicitly defined if its definition is required.

For the second sentence

The definition of the class template explicit specialization shall be reachable from the definition of any member of it.

Isn't that the definition of the class explicit specialization shall be reachable? I think it should be that

The definition of the class or class template explicit specialization shall be reachable from the definition of any member of it.

For the third sentence

The definition of an explicitly specialized class is unrelated to the definition of a generated specialization. That is, its members need not have the same names, types, etc. as the members of a generated specialization.

Again, the same is true when it is the definition of an explicitly specialized class template. It should be that

The definition of an explicitly specialized class or class template is unrelated to the definition of a generated specialization or the class template. That is, its members need not have the same names, types, etc. as the members of a generated specialization.

template<class T>
struct A{
  template<class U>
 struct B{};  //#1
};
template<>
template<class T>
struct A<int>::B{};  //#2

template<>
template<>
struct A<short>::B<int>{}; //#3

Both the definition of #2 and #3 are unrelated to that of #1

For the fourth sentence

Members of an explicitly specialized class template are defined in the same manner as members of normal classes, and not using the template<> syntax. The same is true when defining a member of an explicitly specialized member class.

Isn't that the same is true when defining the member of an explicitly specialized member class template?

Members of an explicitly specialized class template are defined in the same manner as members of normal classes, and not using the template<> syntax. The same is true when defining a member of an explicitly specialized member class template or member class.

@jensmaurer
Copy link
Member

There is no such thing as an "explicitly specialized class". There are classes, class templates, and explicit specializations of class templates (also called "class template explicit specialization"). The first sentence you quote is simply missing "template" at the end. I haven't waded through the rest of it, but likely "template" is missing in a few places.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 30, 2021

@jensmaurer I haven't waded through the rest of it

If you have done that, you would find many defects in this whole clause [temp.expl.spec], I believe. I'm implying CWG529


Incidentally, I think it may exist the (member) class explicit specialization, consider the following case

template<class T>
struct A{
  class B{};
};
template<>
struct A<int>::B{ int b;};  // class explicit specialization for the enclosing class template specialization.

In this case, B is a templated class instead of a class template, we can declare the explicit specialization for this templated class. I also think [temp.expl.spec] p6 should uniformly apply to either case(class template explicit specialization or class explicit specialization).

@jensmaurer
Copy link
Member

This reading does not make sense: You can also explicitly specialize a member function of a class template, but your reading doesn't provide for that. I think we're simply missing a few "template" words in p6.

@JohelEGP
Copy link
Contributor

template<class T>
struct A{
  class B{};
};
template<>
struct A<int>::B{ int b;};  // class explicit specialization for the enclosing class template specialization.

That's an explicit specialization for A<int>::B. Paragraph 6 would apply if it were a member B of an explicitly specialized A<int>. But in this example, A<int> is not explicitly specialized.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 31, 2021

The definition of an explicitly specialized class is unrelated to the definition of a generated specialization.

The above rule in paragraph 6 may cover the case I mentioned if we could say the A<int>::B is an explicitly specialized class. However, What I'm concerning is the above rule should have also covered an explicitly specialized class template that is a member class template or other entity that can be explicitly specialized.

template<class T>
struct D{
  template<class U>
  struct E{};  //#1
};
template<>
template<class U>
struct D<int>::E{
   U member_;
};

Since we explicitly specialized the member class template for class template specialization D< int >, hence the definition of the explicitly specialized member class template is unrelated to that at #1, paragraph 6 should also cover this case. Maybe, the rule could extend to that

The definition of an explicitly specialized entity is unrelated to the definition of that entity or generated specialization from that entity.


Incidentally, template<> struct A<int>::B{/*...*/} is an explicit specialization of the member class B as @JohelEGP said(and I also meant that meaning in the above comment), instead of an explicit specialization of the enclosing class template. This concern comes from the meaning of the wording "explicit specialized", which is given multi-meaning in [temp.expl.spec], which is covered by CWG529.

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

3 participants