Bug 16889 - [3.4 Regression] ambiguity is not detected
Summary: [3.4 Regression] ambiguity is not detected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.1
: P3 minor
Target Milestone: 3.4.2
Assignee: Nathan Sidwell
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 12944
  Show dependency treegraph
 
Reported: 2004-08-05 19:30 UTC by Dima Volodin
Modified: 2004-10-30 21:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.4 4.0.0
Known to fail: 3.4.0
Last reconfirmed: 2004-08-05 19:34:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dima Volodin 2004-08-05 19:30:01 UTC
Ambiguity is not detected in this code:

// start of code
class B {
public:
    B* p;
    B* f();
    virtual ~B();
};

class B1 : virtual public B {
};

class B2 : virtual public B {
};

class B3 : public B {
};

class BB : public B1, public B2, public B3 {
};

#include <iostream>

B*
B::f ()
{
    std::cout << this << std::endl;

    return this;
}

B::~B()
{
    std::cout << this << ".~B()" << std::endl;
}

int
main ()
{
    BB b;
    b.B1::f();
    b.B2::f();
    b.B3::f();
    b.f();
}
// end of code

2.95.3 correctly rejects this code.
Comment 1 Andrew Pinski 2004-08-05 19:34:53 UTC
Confirmed.
Comment 2 Wolfgang Bangerth 2004-08-05 20:31:22 UTC
This is the obvious minimal example: 
---------------------------- 
struct B { 
    int f(); 
}; 
 
struct B1 : virtual B {}; 
struct B2 : B {}; 
struct BB : B1, B2 {}; 
 
int i = BB().f(); 
------------------------------------- 
 
g/x> ~/bin/gcc-3.4*/bin/c++ -c x.cc 
 
g/x> ~/bin/gcc-3.3/bin/c++ -c x.cc 
x.cc:9: error: request for member `f' is ambiguous 
x.cc:2: error: candidates are: int B::f() 
x.cc:2: error:                 int B::f() 
 
To my great surprise, the picture changes once one makes member function f() a  
member _variable_: 
--------------------------- 
struct B { 
    int i; 
}; 
 
struct B1 : virtual B {}; 
struct B2 : B {}; 
struct BB : B1, B2 {}; 
 
int i = BB().i; 
------------------------------------ 
 
In this case, gcc3.4 suddently does spit out an error message (though not a very 
enlightening) whereas 3.3 shows the same message as before: 
 
g/x> ~/bin/gcc-3.4*/bin/c++ -c x.cc 
x.cc:9: error: `B' is an ambiguous base of `BB' 
 
g/x> ~/bin/gcc-3.3/bin/c++ -c x.cc 
x.cc:9: error: request for member `i' is ambiguous 
x.cc:2: error: candidates are: int B::i 
x.cc:2: error:                 int B::i 
 
W. 
Comment 3 Andrew Pinski 2004-08-05 20:36:30 UTC
: Search converges between 2003-02-19-trunk (#187) and 2003-02-20-trunk (#188).
Comment 4 Andrew Pinski 2004-08-05 20:48:57 UTC
Most likely caused by:
2003-02-20  Nathan Sidwell  <nathan@codesourcery.com>

        Change base class access representation. Share virtual base
        binfos.
        * cp/call.c (build_special_member_call): Remove binfo_for_vbase
        call.
        * cp/class.c (build_base_path): Likewise.
        ....
Comment 5 CVS Commits 2004-08-24 16:06:37 UTC
Subject: Bug 16889

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2004-08-24 16:06:22

Modified files:
	gcc/cp         : ChangeLog search.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: ambig1.C ambig2.C 

Log message:
	cp:
	PR c++/16889
	* (is_subobject_of_p): Resurrect & optimize.
	(lookup_field_r): Use it.
	testsuite:
	PR c++/16889
	* g++.dg/lookup/ambig[12].C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4299&r2=1.4300
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.310&r2=1.311
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4181&r2=1.4182
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ambig1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ambig2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Nathan Sidwell 2004-08-24 16:18:47 UTC
	PR c++/16889
	* (is_subobject_of_p): Resurrect & optimize.
	(lookup_field_r): Use it.
Comment 8 CVS Commits 2004-09-24 14:05:05 UTC
Subject: Bug 16889

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2004-09-24 14:04:59

Modified files:
	gcc/cp         : search.c ChangeLog 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: ambig3.C 

Log message:
	cp:
	PR c++/16889
	* search.c (lookup_field_queue_p): Correct check for hidden base.
	
	* search.c (bfs_walk): Remove.
	(lookup_member): Use dfs_walk_real.
	(dfs_walk_real): Move and adjust documentation from bfs_walk.
	testsuite:
	PR c++/16889
	* g++.dg/lookup/ambig3.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.321&r2=1.322
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4383&r2=1.4384
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4341&r2=1.4342
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/ambig3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1