public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/37862]  New: Parenthesised indirection alters class member access
@ 2008-10-17  8:54 nickc at redhat dot com
  2008-10-18 11:12 ` [Bug c++/37862] " rguenth at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: nickc at redhat dot com @ 2008-10-17  8:54 UTC (permalink / raw)
  To: gcc-bugs

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


-- 
           Summary: Parenthesised indirection alters class member access
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: nickc at redhat dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
@ 2008-10-18 11:12 ` rguenth at gcc dot gnu dot org
  2008-11-10 13:37 ` nickc at redhat dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-10-18 11:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-10-18 11:11 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-10-18 11:11:07
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
  2008-10-18 11:12 ` [Bug c++/37862] " rguenth at gcc dot gnu dot org
@ 2008-11-10 13:37 ` nickc at redhat dot com
  2008-11-10 13:51 ` nickc at redhat dot com
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nickc at redhat dot com @ 2008-11-10 13:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from nickc at redhat dot com  2008-11-10 13:36 -------
Created an attachment (id=16644)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16644&action=view)
Allow postfix parser to pass cp_id_kind information back to the primary parser


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
  2008-10-18 11:12 ` [Bug c++/37862] " rguenth at gcc dot gnu dot org
  2008-11-10 13:37 ` nickc at redhat dot com
@ 2008-11-10 13:51 ` nickc at redhat dot com
  2008-11-10 16:23 ` nickc at redhat dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nickc at redhat dot com @ 2008-11-10 13:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from nickc at redhat dot com  2008-11-10 13:49 -------
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


-- 

nickc at redhat dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
                   ` (2 preceding siblings ...)
  2008-11-10 13:51 ` nickc at redhat dot com
@ 2008-11-10 16:23 ` nickc at redhat dot com
  2008-11-10 16:24 ` nickc at redhat dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nickc at redhat dot com @ 2008-11-10 16:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from nickc at redhat dot com  2008-11-10 16:22 -------
Created an attachment (id=16645)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16645&action=view)
Testcase for the bug


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
                   ` (3 preceding siblings ...)
  2008-11-10 16:23 ` nickc at redhat dot com
@ 2008-11-10 16:24 ` nickc at redhat dot com
  2009-01-14 13:00 ` nickc at gcc dot gnu dot org
  2009-02-10 23:11 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: nickc at redhat dot com @ 2008-11-10 16:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from nickc at redhat dot com  2008-11-10 16:22 -------
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


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
                   ` (4 preceding siblings ...)
  2008-11-10 16:24 ` nickc at redhat dot com
@ 2009-01-14 13:00 ` nickc at gcc dot gnu dot org
  2009-02-10 23:11 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: nickc at gcc dot gnu dot org @ 2009-01-14 13:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from nickc at gcc dot gnu dot org  2009-01-14 13:00 -------
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


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/37862] Parenthesised indirection alters class member access
  2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
                   ` (5 preceding siblings ...)
  2009-01-14 13:00 ` nickc at gcc dot gnu dot org
@ 2009-02-10 23:11 ` jason at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu dot org @ 2009-02-10 23:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from jason at gcc dot gnu dot org  2009-02-10 23:11 -------
Fixed.


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37862


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-02-10 23:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-17  8:54 [Bug c++/37862] New: Parenthesised indirection alters class member access nickc at redhat dot com
2008-10-18 11:12 ` [Bug c++/37862] " rguenth at gcc dot gnu dot org
2008-11-10 13:37 ` nickc at redhat dot com
2008-11-10 13:51 ` nickc at redhat dot com
2008-11-10 16:23 ` nickc at redhat dot com
2008-11-10 16:24 ` nickc at redhat dot com
2009-01-14 13:00 ` nickc at gcc dot gnu dot org
2009-02-10 23:11 ` jason at gcc dot gnu dot 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).