V
vanyacpp
Hello,
If I compile the following program with gcc, clang or comeau I get a error about ambiguity. Is this correct behavior?
struct a
{
int foo;
};
struct a2 : virtual a
{};
struct b : a2
{};
struct c : a2
{};
struct d : b, c
{
void f()
{
b::a2::foo; // OK for MSVC, ERROR for others
}
};
(clang) error: ambiguous conversion from derived class 'd' to base class 'a2':
struct d -> struct b -> struct a2
struct d -> struct c -> struct a2
(gcc) error: 'a2' is an ambiguous base of 'd'
(comeau) error: base class "a2" is ambiguous
I explicitly specified that I want a2 in b. Why is there an ambiguity? I've looked in [basic.lookup.qual] and [class.member.lookup] and I haven't found anything relevant.
msvc doesn't show error about an ambiguity, but it also doesn't show errors in very simple cases (see below), so I don't take its results seriously.
struct a
{
int x;
};
struct b : a
{};
struct c : a
{};
struct x : b, c
{
void g()
{
a::x = 5; // OK for MSVC (and uses x->b->a), ERROR for others
}
};
Thanks in advance.
If I compile the following program with gcc, clang or comeau I get a error about ambiguity. Is this correct behavior?
struct a
{
int foo;
};
struct a2 : virtual a
{};
struct b : a2
{};
struct c : a2
{};
struct d : b, c
{
void f()
{
b::a2::foo; // OK for MSVC, ERROR for others
}
};
(clang) error: ambiguous conversion from derived class 'd' to base class 'a2':
struct d -> struct b -> struct a2
struct d -> struct c -> struct a2
(gcc) error: 'a2' is an ambiguous base of 'd'
(comeau) error: base class "a2" is ambiguous
I explicitly specified that I want a2 in b. Why is there an ambiguity? I've looked in [basic.lookup.qual] and [class.member.lookup] and I haven't found anything relevant.
msvc doesn't show error about an ambiguity, but it also doesn't show errors in very simple cases (see below), so I don't take its results seriously.
struct a
{
int x;
};
struct b : a
{};
struct c : a
{};
struct x : b, c
{
void g()
{
a::x = 5; // OK for MSVC (and uses x->b->a), ERROR for others
}
};
Thanks in advance.