[PATCH] D142630: [clang][Interp] Implement virtual function calls
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 7 12:32:55 PST 2023
aaron.ballman added a comment.
In D142630#4110839 <https://reviews.llvm.org/D142630#4110839>, @tbaeder wrote:
> Hmm, this doesn't work if the callee is somewhere in between the path from the dynamic to the static type, e.g.
>
> struct A {
> virtual constexpr int foo() const { return 1; }
> };
>
> struct B : A {
> virtual constexpr int foo() const { return A::foo(); }
> };
>
> constexpr B a;
> static_assert(a.foo() == 1);
>
> For the `A::foo()` call, the type of the `This` pointer is `B`, so we will just select the `B::foo()` to call.
Ah, it sounds like we're not handling qualified calls properly. That makes me think of a few more test cases:
struct A {
virtual constexpr int foo() const { return 1; }
};
struct B : A {
// Same behavior as your test case but with more baffling syntax. :-)
virtual constexpr int foo() const { return this->A::foo(); }
};
constexpr B a;
static_assert(a.foo() == 1);
or with shadowed member variables (not related to virtual functions directly, but is related to qualified lookup):
struct A {
virtual constexpr int foo() const { return 0; }
int Val = 1;
};
struct B : A {
virtual constexpr int foo() const { return A::Val; }
int Val = 2;
};
constexpr B a;
static_assert(a.foo() == 1);
note, the rules are different for constructors and destructors than they are for other functions, so similar test cases involving those would be a good idea as well (though perhaps in a separate patch).
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142630/new/
https://reviews.llvm.org/D142630
More information about the cfe-commits
mailing list