decltype of a member function

decltype of a member function

Post by CornedBe » Tue, 12 Jan 2010 09:48:30


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.yqcomputer.com/ ]
 
 
 

decltype of a member function

Post by Nikolay Iv » Tue, 12 Jan 2010 19:39:52


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 members 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.yqcomputer.com/ ]

 
 
 

decltype of a member function

Post by litb » Tue, 12 Jan 2010 19:40:25


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.yqcomputer.com/ ]
 
 
 

decltype of a member function

Post by Nick Houns » Tue, 12 Jan 2010 19:40:27


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.yqcomputer.com/ ]