16889 – [3.4 Regression] ambiguity is not detected (original) (raw)

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

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 Drea 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 Drea Pinski 2004-08-05 20:36:30 UTC

: Search converges between 2003-02-19-trunk (#187) and 2003-02-20-trunk (#188).

Comment 4 Drea 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 6 Nathan Sidwell 2004-08-24 16🔞47 UTC

[PR c++/16889](show%5Fbug.cgi?id=16889 "RESOLVED FIXED - [3.4 Regression] ambiguity is not detected")
* (is_subobject_of_p): Resurrect & optimize.
(lookup_field_r): Use it.