public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aschepler at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/11750] class scope using-declaration lookup not implemented
Date: Wed, 12 Jan 2011 18:24:00 -0000	[thread overview]
Message-ID: <bug-11750-4-YhT7mxfZN8@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-11750-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Andrew Schepler <aschepler at gmail dot com> 2011-01-12 17:16:29 UTC ---
(In reply to comment #6)
> > struct A {
> >     virtual void f();
> > };
> > struct B : virtual A {
> >     virtual void f();
> > };
> > 
> > struct C : B , virtual A {
> >     using A::f; 
> > };

> Im using g++ 4.4.5
> With the same example with my main function as below,
> int main()
> {
>       C c;
>       c.f() // Calls A::f
>       C* pc = &c;
>       pc->f() // Calls B::f
> }
> 
> With the same object when accessed directly produces different results and when
> accessed using a pointer of same type produces a different result. Even if gcc
> violates standard, there has to be some proper explanation.

The reason is that when f is invoked via a pointer or reference, g++ uses the
vtable lookup to call the correct final override.  But when the object in the
member access is not a pointer or reference (it is a non-reference identifier
as here, or qualified id, or class member), g++ can usually optimize away the
virtual call and just call the correct member function.  In this case the logic
for calling the correct member function for that optimization is incorrect, but
virtual calls still work correctly.


  parent reply	other threads:[~2011-01-12 17:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
2011-01-12 17:06 ` balakrishnan.erode at gmail dot com
2011-01-12 17:20 ` redi at gcc dot gnu.org
2011-01-12 18:24 ` aschepler at gmail dot com [this message]
2011-11-21 22:32 ` fabien at gcc dot gnu.org
2012-11-14 20:13 ` fabien at gcc dot gnu.org
2012-11-14 20:20 ` fabien at gcc dot gnu.org
2021-08-02  0:15 ` pinskia at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-11750-4-YhT7mxfZN8@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).