Open AlexeySachkov opened 3 months ago
I.e. even if a selected function is virtual, but the class member access expression is in a certain form, the call is not considered to be a virtual call, but instead it is just a direct call to the said function. I'm properly lost in all those id-expression, qualified-id and other terms from the C++ draft spec, but my understanding is that there is no virtual call mechanism involved in an example below:
I think this is the case that expr.call.2 refers to:
struct Base {
virtual void foo();
};
struct Derive : public Base {
virtual void foo();
};
int main() {
Derive d;
Base *b = &d;
b->Base::foo(); // Non-virtual function call to Base::foo
}
I.e. we only disallow cases where virtual call mechanism is involved, but we allow direct (i.e. non-virtual) calls to functions that are defined as virtual.
Yes, I agree. I think this proposed change makes sense. We will need to update the error checking in DPC++, though, because we currently diagnose both cases as an error.
5.4. Language restrictions for device functions lists the following restriction (emphasis mine):
As I read this, no call to a virtual member function is allowed, even if the call is in fact direct, i.e. it does not involve virtual call mechanism. There are a few situations where the latter could occur:
From class.virtual.16:
Also, expr.call.2 (emphasis mine) suggests that there are cases when a call to a virtual member function is not considered to be a virtual call:
I.e. even if a selected function is virtual, but the class member access expression is in a certain form, the call is not considered to be a virtual call, but instead it is just a direct call to the said function. I'm properly lost in all those
id-expression
,qualified-id
and other terms from the C++ draft spec, but my understanding is that there is no virtual call mechanism involved in an example below:If my reading of both specs is correct, then we should update the restriction in the SYCL spec to say something like this (emphasis to highlight the diff):
I.e. we only disallow cases where virtual call mechanism is involved, but we allow direct (i.e. non-virtual) calls to functions that are defined as virtual.