[PATCH] D142630: [clang][Interp] Implement virtual function calls
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 9 11:05:39 PDT 2023
aaron.ballman added inline comments.
================
Comment at: clang/lib/AST/Interp/Interp.h:1560
+ // is the furthest we might go up in the hierarchy.
+ ThisPtr = ThisPtr.getDeclPtr();
+ }
----------------
tbaeder wrote:
> I think this test case was from the function pointer review, but this fixes:
> ```
> struct S {
> virtual constexpr int func() const { return 1; }
> };
>
> struct Middle : S {
> constexpr Middle(int i) : i(i) {}
> int i;
> };
>
> struct Other {
> constexpr Other(int k) : k(k) {}
> int k;
> };
>
> struct S2 : Middle, Other {
> int j;
> constexpr S2(int i, int j, int k) : Middle(i), Other(k), j(j) {}
> virtual constexpr int func() const { return i + j + k + S::func(); }
> };
>
>
> constexpr S s;
> constexpr decltype(&S::func) foo = &S::func;
> constexpr S2 s2(1, 2, 3);
> constexpr int value3 = (s2.*foo)();
> ```
>
> even I am confused by all of this now, so the comment might not be the clearest :)
>
> (I did not add that test case since it needs other changes in`classify()` and `VisitBinaryOperator()`, but can do that in a follow-up commit.)
Please do add the example in a follow-up.
================
Comment at: clang/test/AST/Interp/records.cpp:650
+};
+#endif
----------------
We should also have test cases for calling virtual functions from within a constructor and a destructor, as that has special semantics. e.g., https://godbolt.org/z/snaj1zfM5
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142630/new/
https://reviews.llvm.org/D142630
More information about the cfe-commits
mailing list