public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11750] class scope using-declaration lookup not implemented
       [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
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: balakrishnan.erode at gmail dot com @ 2011-01-12 17:06 UTC (permalink / raw)
  To: gcc-bugs

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

Balakrishnan B <balakrishnan.erode at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |balakrishnan.erode at gmail
                   |                            |dot com

--- Comment #6 from Balakrishnan B <balakrishnan.erode at gmail dot com> 2011-01-12 16:57:07 UTC ---
(In reply to comment #0)
> Paragraph 10.3/2 in the C++ standard [ISO/IEC 14882:1998] provides the
> following
> code example:
> 
> <quote>
> 
> struct A {
>     virtual void f();
> };
> struct B : virtual A {
>     virtual void f();
> };
> 
> struct C : B , virtual A {
>     using A::f; 
> };
> void foo() {
>     C c; 
>     c.f();      // calls B::f, the final overrider
>     c.C::f();   // calls A::f because of the using-declaration
> }
> 
> </quote>
> 
> When a similar program is compiled using G++ 3.3, the method call 'c.f()' in
> function foo() incorrectly invokes A::f and not B::f as specified in the
> standard.
> 
> <example>
> <code main.cpp>
> #include <iostream>
> 
> struct A {
>     virtual void f() { std::cout << "A::f()\n"; }
> };
> struct B : virtual A {
>     virtual void f() { std::cout << "B::f()\n"; }
> };
> struct C : B, virtual A {
>     using A::f;
> };
> 
> int main()
> {
>     C c;
>     c.f();      // ERROR - Incorrectly invokes A::f
>     c.C::f();   // OK - Invokes A::f
> }
> </code>
> 
> <build>
> $ g++ main.cpp
> 
> $ ldd a.out
>         libstdc++.so.5 =>
> /usr/local/gcc/3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/libstdc++.so.5
> (0x40017000)
>         libm.so.6 => /lib/tls/libm.so.6 (0x400e4000)
>         libgcc_s.so.1 =>
> /usr/local/gcc/3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc_s.so.1 (0x40106000)
>         libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
>         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
> </build>
> 
> <output>
> $ ./a.out
> A::f()
> A::f()
> </output>
> 
> </example>

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.


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

* [Bug c++/11750] class scope using-declaration lookup not implemented
       [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
  2011-01-12 17:06 ` [Bug c++/11750] class scope using-declaration lookup not implemented 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
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2011-01-12 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-01-12 17:10:17 UTC ---
(In reply to comment #6)
> 
> 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 explanation is "it's a bug"


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

* [Bug c++/11750] class scope using-declaration lookup not implemented
       [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
  2011-01-12 17:06 ` [Bug c++/11750] class scope using-declaration lookup not implemented 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
  2011-11-21 22:32 ` fabien at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: aschepler at gmail dot com @ 2011-01-12 18:24 UTC (permalink / raw)
  To: gcc-bugs

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.


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

* [Bug c++/11750] class scope using-declaration lookup not implemented
       [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2011-01-12 18:24 ` aschepler at gmail dot com
@ 2011-11-21 22:32 ` fabien at gcc dot gnu.org
  2012-11-14 20:13 ` fabien at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 7+ messages in thread
From: fabien at gcc dot gnu.org @ 2011-11-21 22:32 UTC (permalink / raw)
  To: gcc-bugs

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

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-12-18 20:22:49         |2011-11-21 20:22:49


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

* [Bug c++/11750] class scope using-declaration lookup not implemented
       [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  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
  6 siblings, 0 replies; 7+ messages in thread
From: fabien at gcc dot gnu.org @ 2012-11-14 20:13 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from fabien at gcc dot gnu.org 2012-11-14 20:12:56 UTC ---
Author: fabien
Date: Wed Nov 14 20:12:47 2012
New Revision: 193504

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193504
Log:
gcc/testsuite/ChangeLog

2012-11-14  Fabien Chêne  <fabien@gcc.gnu.org>

    PR c++/11750
    * g++.dg/inherit/vitual9.C: New.

gcc/cp/ChangeLog

2012-11-14  Fabien Chêne  <fabien@gcc.gnu.org>

    PR c++/11750
    * call.c (build_new_method_call_1): Check that the instance type
    and the function context are the same before setting the flag
    LOOKUP_NONVIRTUAL.

Added:
    trunk/gcc/testsuite/g++.dg/inherit/virtual9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/11750] class scope using-declaration lookup not implemented
       [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  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
  6 siblings, 0 replies; 7+ messages in thread
From: fabien at gcc dot gnu.org @ 2012-11-14 20:20 UTC (permalink / raw)
  To: gcc-bugs


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

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.8.0

--- Comment #10 from fabien at gcc dot gnu.org 2012-11-14 20:20:21 UTC ---
Fixed in 4.8.


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

* [Bug c++/11750] class scope using-declaration lookup not implemented
       [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2012-11-14 20:20 ` fabien at gcc dot gnu.org
@ 2021-08-02  0:15 ` pinskia at gcc dot gnu.org
  6 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-02  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |meng at g dot clemson.edu

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 55385 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-08-02  0:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-11750-4@http.gcc.gnu.org/bugzilla/>
2011-01-12 17:06 ` [Bug c++/11750] class scope using-declaration lookup not implemented 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
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

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).