Is the following standard conforming? Can you cite the section?
struct A
{
virtual void func() = 0;
};
struct B
{
void func(){}
};
struct C : public A, public B
{
virtual void func(){ B::func(); }
};
I’m getting a strange compiler warning in VS2010 in equivalent but more complicated code pointing to func‘s declaration in the derived-most class: warning C4505: unreferenced local function has been removed. I have no idea why the compiler thinks a virtual function declared in a class is a local; however I can’t repro that warning in a simpler example.
Edit:
I figured out a small repro case for the warning. I think I was going down the wrong path assuming it was related to function hiding. Here’s the repro case:
template<typename T>
struct C
{
int GetType() const;
virtual int func() const; // {return 4;} // Doing this inline removes the warning <--------------
};
template<typename T>
int C<T>::GetType() const
{
return 0;
}
template<>
int C<int>::GetType() const
{
return 12;
}
template<typename T>
int C<T>::func() const
{
return 3;
}
// Adding the following removes the warning <--------------------
// template<>
// int C<int>::func() const
// {
// return 4;
// }
I’m fairly sure this is just a VS2010 bug.
The code is well-formed.
C::funcoverridesA::func.B::funcis an unrelated function. The spec reads (10.3/2):C::funchas the same name asA::funcandA::funcis virtual, thereforeC::funcoverridesA::func.B::funchas no relation toA::func; I don’t know that there is any language in the spec that expressly addresses that scenario.The Visual C++ 11 Beta compiler does not emit any warnings or errors for this code.