Hi Guys, Compiling and then executing this program: #include <stdio.h> class A { public: virtual void get() { printf ("A\n"); } }; class B:public A { public: virtual void get() { printf ("B\n"); } }; class C:public B { }; int main (void) { C c; C* p = &c; p->A::get(); (p->A::get)(); return 0; } Results in: A B Being displayed, rather than: A A As far as I can tell the parentheses around the class member access should not change anything. Cheers Nick
Confirmed.
Created attachment 16644 [details] Allow postfix parser to pass cp_id_kind information back to the primary parser
Hi Guys, I have uploaded a potential patch for the problem. It fixes the testcase originally provided and does not introduce any regressions into the g++ testsuite for an i686-pc-linux-gnu toolchain. That's the good news. The bad news is that I am not sure if the patch will be acceptable since I am not a C++ expert. The problem I believe is that the status of the cp_id_kind enum which is computed by cp_parser_postfix_dot_deref_expression() when it is parsing "A::get" is not passed back to cp_parse_primary_expression() which is currently parsing "(p->A::get)". So it goes with its default value, which allows overloading of virtual functions, and so the wrong member function is selected. The patch attempts to fix this problem by allowing the cp_id_kind enum computed in cp_parser_postfix_dot_deref_expression to be passes back, via a long chain of intermediary functions, to cp_parser_primary_expression. My concern is that I am not familiar enough with the C++ parser to tell if the patch breaks some other parser requirement. (One that is not tested by the g++ testsuite). So - is this patch acceptable ? Cheers Nick
Created attachment 16645 [details] Testcase for the bug
Oops - almost forgot - the bug needs a testcase for the g++ testsuite, so I have uploaded a patch to add that as well. Cheers Nick
Subject: Bug 37862 Author: nickc Date: Wed Jan 14 13:00:21 2009 New Revision: 143369 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143369 Log: PR c++/37862 * parser.c: Pass cp_id_kind computed in cp_parser_postfix_dot_deref_expression to cp_parser_primary_expression. * g++.cp/parse/pr37862.C: New test. Added: trunk/gcc/testsuite/g++.dg/parse/pr37862.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/parser.c trunk/gcc/testsuite/ChangeLog
Fixed.