public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52453] New: compiling error when get address of a virtual function(invalid use of non-static member function)
@ 2012-03-01 16:10 wildpointercs at gmail dot com
2012-03-01 16:34 ` [Bug c++/52453] " redi at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: wildpointercs at gmail dot com @ 2012-03-01 16:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453
Bug #: 52453
Summary: compiling error when get address of a virtual
function(invalid use of non-static member function)
Classification: Unclassified
Product: gcc
Version: 4.2.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: wildpointercs@gmail.com
Version:gcc4.2.4,
System :Ubuntu Linux 2.6.24
The preprocessed file:
# 1 "test.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.cpp"
class Test
{
public:
virtual void func(char *p){}
};
int main()
{
typedef void (Test::*pTestfunc)(char *);
pTestfunc pf = &(Test::func); // error here.
}
Error message: invalid use of non-static member function 'virtual void
Test::func(char *)'
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/52453] compiling error when get address of a virtual function(invalid use of non-static member function)
2012-03-01 16:10 [Bug c++/52453] New: compiling error when get address of a virtual function(invalid use of non-static member function) wildpointercs at gmail dot com
@ 2012-03-01 16:34 ` redi at gcc dot gnu.org
2012-03-01 16:40 ` wildpointercs at gmail dot com
2012-03-01 16:43 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-01 16:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-01 16:34:29 UTC ---
GCC 4.2 is no longer supported, but it doesn't matter because your code is
invalid anyway.
To take the address of a member function you must not use parentheses around
the expression:
pTestfunc pf = &Test::func;
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/52453] compiling error when get address of a virtual function(invalid use of non-static member function)
2012-03-01 16:10 [Bug c++/52453] New: compiling error when get address of a virtual function(invalid use of non-static member function) wildpointercs at gmail dot com
2012-03-01 16:34 ` [Bug c++/52453] " redi at gcc dot gnu.org
@ 2012-03-01 16:40 ` wildpointercs at gmail dot com
2012-03-01 16:43 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: wildpointercs at gmail dot com @ 2012-03-01 16:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453
--- Comment #2 from Allen Wu <wildpointercs at gmail dot com> 2012-03-01 16:40:07 UTC ---
Thank you for your response.
But I cannot see any difference between &Test::func and &(Test::func). Does
C++ standard specify &(Test::func) is illegal?
Thanks in advance.
Allen
2012/3/2 redi at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453
>
> Jonathan Wakely <redi at gcc dot gnu.org> changed:
>
> What |Removed |Added
>
> ----------------------------------------------------------------------------
> Status|UNCONFIRMED |RESOLVED
> Resolution| |INVALID
>
> --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-01
> 16:34:29 UTC ---
> GCC 4.2 is no longer supported, but it doesn't matter because your code is
> invalid anyway.
>
> To take the address of a member function you must not use parentheses
> around
> the expression:
>
> pTestfunc pf = &Test::func;
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/52453] compiling error when get address of a virtual function(invalid use of non-static member function)
2012-03-01 16:10 [Bug c++/52453] New: compiling error when get address of a virtual function(invalid use of non-static member function) wildpointercs at gmail dot com
2012-03-01 16:34 ` [Bug c++/52453] " redi at gcc dot gnu.org
2012-03-01 16:40 ` wildpointercs at gmail dot com
@ 2012-03-01 16:43 ` redi at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2012-03-01 16:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52453
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-01 16:42:42 UTC ---
yes, the C++ standard is very clear about this:
A pointer to member is only formed when an explicit & is used and its operand
is a qualified-id not enclosed in parentheses. [ Note: that is, the expression
&(qualified-id), where the qualified-id is enclosed in parentheses, does not
form an expression of type “pointer to member.” Neither does qualified-id,
because there is no implicit conversion from a qualified-id for a non-static
member function to the type “pointer to member function” as there is from an
lvalue of function type to the type “pointer to function” (4.3). Nor is
&unqualified-id a pointer to member, even within the scope of the
unqualified-id’s class. —end note ]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-01 16:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-01 16:10 [Bug c++/52453] New: compiling error when get address of a virtual function(invalid use of non-static member function) wildpointercs at gmail dot com
2012-03-01 16:34 ` [Bug c++/52453] " redi at gcc dot gnu.org
2012-03-01 16:40 ` wildpointercs at gmail dot com
2012-03-01 16:43 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).