Topic: decltype of a member function
Author: CornedBee <wasti.redl@gmx.net>
Date: Mon, 11 Jan 2010 00:48:30 CST Raw View
What is the decltype of a member function? The current draft says that
when the operand to decltype names a declaration, the resulting type
is the type of the declaration. But what is the type of member
functions?
struct A {
void f() {
decltype(f) fn; // What does this attempt to declare?
}
};
Sebastian
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Nikolay Ivchenkov <tsoae@mail.ru>
Date: Mon, 11 Jan 2010 10:39:52 CST Raw View
On 11 Jan, 09:48, CornedBee <wasti.r...@gmx.net> wrote:
> What is the decltype of a member function? The current draft says that
> when the operand to decltype names a declaration, the resulting type
> is the type of the declaration. But what is the type of member
> functions?
>
> struct A {
> void f() {
> decltype(f) fn; // What does this attempt to declare?
> }
>
> };
decltype cannot be applied to a non-static member function. See N3000
- 5.1.1/10:
"An id-expression that denotes a non-static data member or non-static
member function of a class can only be used:
as part of a class member access (5.2.5) in which the object-
expression refers to the member s class or a class derived from that
class, or
to form a pointer to member (5.3.1), or
in the body of a non-static member function of that class or of a
class derived from that class (9.3.1), or
in a mem-initializer for a constructor for that class or for a class
derived from that class (12.6.2), or in a brace-or-equal-initializer
for a non-static data member of that class or of a class derived from
that class (12.6.2), or
if that id-expression denotes a non-static data member and it
appears in an unevaluated operand",
and 9.3.1/3:
"When an id-expression (5.1) that is not part of a class member access
syntax (5.2.5) and not used to form a pointer to member (5.3.1) is
used in the body of a non-static member function of class X, if name
lookup (3.4.1) resolves the name in the id-expression to a non-static
non-type member of some class C, the id-expression is transformed into
a class member access expression (5.2.5) using (*this) (9.3.2) as the
postfix-expression to the left of the . operator.",
and 5.2.5/4:
"[...]
Otherwise, if E1.E2 refers to a non-static member function and the
type of E2 is function of parameter-type-list cv ref-qualifier opt
returning T , then E1.E2 is an rvalue. The expression designates a non-
static member function. The expression can be used only as the left-
hand operand of a member function call (9.3)."
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Nick Hounsome <nick.hounsome@googlemail.com>
Date: Mon, 11 Jan 2010 10:40:27 CST Raw View
On 11 Jan, 06:48, CornedBee <wasti.r...@gmx.net> wrote:
> What is the decltype of a member function? The current draft says that
> when the operand to decltype names a declaration, the resulting type
> is the type of the declaration. But what is the type of member
> functions?
>
> struct A {
> void f() {
> decltype(f) fn; // What does this attempt to declare?
> }
>
> };
>
Presumably void (A::*)() because then you can write:
fn = A::f;
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: litb <Schaub-Johannes@web.de>
Date: Mon, 11 Jan 2010 10:40:25 CST Raw View
On 11 Jan., 07:48, CornedBee <wasti.r...@gmx.net> wrote:
> What is the decltype of a member function? The current draft says that
> when the operand to decltype names a declaration, the resulting type
> is the type of the declaration. But what is the type of member
> functions?
>
> struct A {
> void f() {
> decltype(f) fn; // What does this attempt to declare?
> }
>
> };
>
I believe (haven't checked the standard yet) that this will undergo
the implicit class member access transformation. So, it's a class
member access expression and it has type "void()" and is an rvalue.
But i think it is against the rule in class member access constraints
that forbids naming a nonstatic member function in a class member
access without applying the function call operator immediately (I
would like to see an exception for unevaluated operands - but i'm not
sure whether there is in this case). But in any case, *if* it is
allowed, it certainly has type "void()". There are no special member
function types or member data types (see somewhere at [class.mem],
where there is a note-paragraph saying exactly that).
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]