Topic: Defect Report: What is a "member function template"?


Author: thornley@visi.com (David Thornley)
Date: 2000/10/12
Raw View
In article <8s1vpr$bin$1@nnrp1.deja.com>,  <wmm@fastdial.net> wrote:
>In article <39E3F363.244D7FF2@wizard.net>,
>  James Kuyper <kuyper@wizard.net> wrote:
>> There are three options: a member function template is either:
>> A) a member function of a class template
>> or
>> B) a function template which is a class member
>> or
>> C) both.
>>
>> The following clauses use the term "member function template":
>
>... extensive survey of usage elided ...
>
>> My guess: B is the correct meaning, which means that the example in
>> 14.5.1.1p1 must be defective.
>
I think so also, but that's not what the standard seems to say in
14.5.1.1.

>Thanks for this analysis.  I think you're right, except that
>what is defective in 14.5.1.1p1 is the use of the phrase
>"member function template."

Does this mean that the mention in 3.2 is misleading, and it should
have another parenthesized section number after "member function
template"?  Maybe 14.5.2?

>(issue #105).  There's a catch-all issue (#205) that deals
>with the general question of when members of template classes
>or of non-template classes nested within template classes
>are treated as templates and when not.  I haven't firmly
>decided yet, but I'll probably extend the description of
>#205 to include this report (as opposed to opening a new
>issue for it).
>
Either way.  I'd like it on the issues list, and I really don't
care where.

>We should have developed a precise vocabulary early on
>and enforced it, but unfortunately we dropped the ball on
>this point.
>
It's always so easy to realize these things when it's too late.
It would be nice to load a saved life file sometimes.


--
David H. Thornley                        | If you want my opinion, ask.
david@thornley.net                       | If you don't, flee.
http://www.thornley.net/~thornley/david/ | O-

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: wmm@fastdial.net
Date: 2000/10/12
Raw View
In article <Sf6F5.296$FU3.48668@ptah.visi.com>,
  thornley@visi.com (David Thornley) wrote:
> Does this mean that the mention in 3.2 is misleading, and it should
> have another parenthesized section number after "member function
> template"?  Maybe 14.5.2?

Speaking for myself (not the Committee), I have a slightly
different take on what should be done to 3.2: a member function
template is a "non-static function template."  That is, it's a
function template that is a member, just as a member class
template is a class template that's a member.  (Cf 14.5.2: "A
template... declared within a class or class template... is
called a member template.")

Thus I think that "member function template" in 3.2p5 should be
changed to "member function of a class template," leaving the
cross reference as is, since member function templates are
already covered by the phrase "non-static function template."

--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: thornley@visi.com (David Thornley)
Date: 11 Oct 00 03:41:35 GMT
Raw View
 [Moderator's note: this defect has been forwarded
 to the C++ committee. -moderator(fjh).]

In 3.2 [basic.def.odr], paragraph 5, the phrase "member function
template(14.5.1.1)" is used, implying that the definition of
"member function template" is there.  (There are other uses of
"member function template" between 3.2 and 14.5.1.1, which do
not give a definition or a reference to 14.5.1.1 or other possible
definition.)

In 14.5.1.1 [temp.mem.func], I cannot find a definition.  Paragraph
1 reads "A member function template may be defined outside of the
class template definition in which it is declared.".  The example
given is one of a template class with three functions declared.
This seems to imply that a member function of a template class is
a member function template, although this is inferring partly from
non-normative text.  The phrase "member function template" is
not used in paragraph 2, although the phrase "member function of a
class template" is.

In 14.5.2 [temp.mem], paragraph 3 reads "A member function template
shall not be virtual."  Paragraph 4 reads "A specialization of a
member function template does not override a virtual function from
a base class."  The examples given are of member functions that
are templates of their own, rather than just being member functions
of a class template.

My specific problem was of the legality of something like this:

class A {
   virtual int f();
}

template<class T>
class B : public A {
   int f();
}

In this case, it is unclear according to the Standard whether this is
a member template function that is virtual (violating paragraph 3)
or if in
A* Ainst = new B<foo>;
Ainst->f() is or is not overridden by B<foo>::f().

The arguments in Stroustrup's books why the Standard reads this way
apply to the examples as given in the Standard, but not the example
I supply.  My interpretation is that there is no reason why the
example supplied above should be considered ill-formed, but the
Standard itself is not clear.

--
David H. Thornley                        | If you want my opinion, ask.
david@thornley.net                       | If you don't, flee.
http://www.thornley.net/~thornley/david/ | O-
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




Author: James Kuyper <kuyper@wizard.net>
Date: 2000/10/11
Raw View
David Thornley wrote:
>
>         [Moderator's note: this defect has been forwarded
>         to the C++ committee. -moderator(fjh).]
>
> In 3.2 [basic.def.odr], paragraph 5, the phrase "member function
> template(14.5.1.1)" is used, implying that the definition of
> "member function template" is there.  (There are other uses of
> "member function template" between 3.2 and 14.5.1.1, which do
> not give a definition or a reference to 14.5.1.1 or other possible
> definition.)
>
> In 14.5.1.1 [temp.mem.func], I cannot find a definition.  Paragraph
> 1 reads "A member function template may be defined outside of the
> class template definition in which it is declared.".  The example
> given is one of a template class with three functions declared.
> This seems to imply that a member function of a template class is
> a member function template, although this is inferring partly from
> non-normative text.  The phrase "member function template" is
> not used in paragraph 2, although the phrase "member function of a
> class template" is.
>
> In 14.5.2 [temp.mem], paragraph 3 reads "A member function template
> shall not be virtual."  Paragraph 4 reads "A specialization of a
> member function template does not override a virtual function from
> a base class."  The examples given are of member functions that
> are templates of their own, rather than just being member functions
> of a class template.
>
> My specific problem was of the legality of something like this:
>
> class A {
>    virtual int f();
> }
>
> template<class T>
> class B : public A {
>    int f();
> }
>
> In this case, it is unclear according to the Standard whether this is
> a member template function that is virtual (violating paragraph 3)
> or if in
> A* Ainst = new B<foo>;
> Ainst->f() is or is not overridden by B<foo>::f().
>
> The arguments in Stroustrup's books why the Standard reads this way
> apply to the examples as given in the Standard, but not the example
> I supply.  My interpretation is that there is no reason why the
> example supplied above should be considered ill-formed, but the
> Standard itself is not clear.

There are three options: a member function template is either:
A) a member function of a class template
or
B) a function template which is a class member
or
C) both.

The following clauses use the term "member function template":

12.8p3: If the meaning were A or C, copy constructors for template
classes could never be instantiated. The example given matches B.

13.1p2:

14.5.1.1p1: The example given matches A.

14.5.2p2: The clause does not make sense if the meaning were A.

14.5.2p3: The example only works with B.

14.5.2p4: If either A or C were meant, template classes with virtual
member functions could never be overriden.

14.5.2p5: The example is of type B.

14.6p5, 14.6.4p1, 14.6.4p7, 14.7.2p4, 14.7.3p1, 14.7.3p7, 14.7.3p21:
Uses both "member function template" and "member function of a class
template", as if they referred to different things.

14.7p2: The fourth sentence is redundant with the third if the meaning
were A.

14.7p3:
14.7.2p3:
14.7.2p6:
14.7.3p19:

14.8.1p5: The reasoning given doesn't apply if the meaning is A.

My guess: B is the correct meaning, which means that the example in
14.5.1.1p1 must be defective.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]






Author: wmm@fastdial.net
Date: 2000/10/11
Raw View
In article <39E3F363.244D7FF2@wizard.net>,
  James Kuyper <kuyper@wizard.net> wrote:
> There are three options: a member function template is either:
> A) a member function of a class template
> or
> B) a function template which is a class member
> or
> C) both.
>
> The following clauses use the term "member function template":

... extensive survey of usage elided ...

> My guess: B is the correct meaning, which means that the example in
> 14.5.1.1p1 must be defective.

Thanks for this analysis.  I think you're right, except that
what is defective in 14.5.1.1p1 is the use of the phrase
"member function template."  The title of the section is
"Member functions of class templates," and the same phrase
ought to be used in 14.5.1.1p1.  (Member function templates
are covered in 14.5.2, "Member templates," which includes
both function and class templates.)

This is just one more example of a fairly pervasive problem
in the Standard regarding the terminology used to describe
template-related concepts.  For instance, there is an issue
that we expect to fix in the first TC regarding consistent
use of "function template" versus "template function"
(issue #105).  There's a catch-all issue (#205) that deals
with the general question of when members of template classes
or of non-template classes nested within template classes
are treated as templates and when not.  I haven't firmly
decided yet, but I'll probably extend the description of
#205 to include this report (as opposed to opening a new
issue for it).

These problems result from the fact that the template
clause underwent almost continual revision during the
production of the Standard over eight years, with lots of
different people contributing wording.  Additionally, a
lot of references to template concepts were sprinkled
through the rest of the Standard by still other people.
We should have developed a precise vocabulary early on
and enforced it, but unfortunately we dropped the ball on
this point.

Again, thanks for your survey; I'll definitely make use of
it in adding this report to the issues list.

--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)


Sent via Deja.com http://www.deja.com/
Before you buy.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]