C++0x, confusion with using-declaration in two base classes

J

Johannes Schaub

What should happen for this case:

struct A {
void f();
};

struct B : virtual A {
using A::f;
};

struct C : virtual A {
using A::f;
};

struct D : B, C {
void g() {
f();
}
};

The line of interest is `f()`. Clearly the lookup of `f` according to
`10.2` of the FDIS succeeds and finds `A::f`. However, what candidates will
overload resolution consider? The spec says at `13.3.1p4`:
For non-conversion functions introduced by a using-declaration into a
derived class, the function is considered to be a member of the derived
class for the purpose of defining the type of the implicit object parameter.

The intent of this is that for a single class, if such a class contains both
own member functions and a using declaration bringing names of base class
functions into scope, that during overload resolution all the function
candidates have the same class type in their implicit object parameter. But
what does this mean for the above example? Will the candidates be the
following?

void F1(B&)
void F2(C&)
// call arguments: (lvalue D)

This appears to be wrong, because we only have one declaration in the lookup
result set according to `10.2p7`. How shall we interpret this??

PS: Please see the "cross-posted"
http://stackoverflow.com/questions/5683687/c0x-confusion-with-using-
declarations . Thanks!
 
A

Alf P. Steinbach /Usenet

* Johannes Schaub, on 16.04.2011 03:17:
What should happen for this case:

struct A {
void f();
};

struct B : virtual A {
using A::f;
};

struct C : virtual A {
using A::f;
};

struct D : B, C {
void g() {
f();
}
};

The line of interest is `f()`. Clearly the lookup of `f` according to
`10.2` of the FDIS succeeds and finds `A::f`. However, what candidates will
overload resolution consider? The spec says at `13.3.1p4`:

derived class, the function is considered to be a member of the derived
class for the purpose of defining the type of the implicit object parameter.

The intent of this is that for a single class, if such a class contains both
own member functions and a using declaration bringing names of base class
functions into scope, that during overload resolution all the function
candidates have the same class type in their implicit object parameter. But
what does this mean for the above example? Will the candidates be the
following?

void F1(B&)
void F2(C&)
// call arguments: (lvalue D)

This appears to be wrong, because we only have one declaration in the lookup
result set according to `10.2p7`. How shall we interpret this??

PS: Please see the "cross-posted"
http://stackoverflow.com/questions/5683687/c0x-confusion-with-using-
declarations . Thanks!

I don't know what the FDIS would say.

I think it's more interesting to first get some consensus about what the result
should be in C++98/03, and then, based on that, whether a DR is needed for the FDIS.

In Windows both g++ and msvc reject the code as ambiguous, and for g++ both for
C++98 and C++0x. That's what I expected. However, Comeau Online accepts it...


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top