[PATCH] D134699: [clang][Interp] Implement This pointer passing to methods

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 6 11:33:49 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/test/AST/Interp/records.cpp:106
+
+constexpr C RVOAndParams(const C *c) {
+  return C();
----------------
tbaeder wrote:
> aaron.ballman wrote:
> > We're missing a fair amount of test coverage here in terms of calling member functions. Can you add some tests for that, as well as a test where the this pointer is invalid and causes UB? e.g.,
> > ```
> > struct S {
> >   constexpr void member() {}
> > };
> > 
> > constexpr void func(S *s) {
> >   s->member(); // Should not be a constant expression
> > }
> > 
> > int main() {
> >   func(nullptr);
> > }
> > ```
> I just checked and we indeed don't reject that example. There are already functions to detect such scenarios in `Interp.h/.cpp`. But actually using them seems to require a bigger surgery since `Call`/`CallVoid` are currenly in both `EvalEmitter.cpp` and `Interp.cpp`.
> 
> I've written this down but I think for this patch it makes sense to add the failing test case and ignore the failure for now.
I'm okay with adding a failure test case with a fixme comment on it for now.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134699/new/

https://reviews.llvm.org/D134699



More information about the cfe-commits mailing list