i found a problem in the following code:
It looks like GCC can only devirtualize the first Interface I_Udc. The Interface GCC is not able to devirtualize the second interface I_Uac. If I write I_Uac first, the I_Uac call will be inlined.
Here is the code at compiler explorer: https://godbolt.org/z/z6WEoznfW
class I_Uac
{
public:
virtual float GetIUac() = 0;
};
class I_Udc
{
public:
virtual float GetIUdc() = 0;
};
class DataAcq final : public I_Udc, public I_Uac
{
float GetIUac()
{
return r;
}
float GetIUdc()
{
return m;
}
private:
float r = 20;
float m = 20;
};
DataAcq temp;
I_Uac& temp1 = temp;
I_Udc& temp2 = temp;
int main ()
{
volatile float r = temp1.GetIUac();
volatile float m = temp2.GetIUdc();
}
So the question is how can i force the compiler to inline both function calls via the interface reference?