[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)
Balázs Benics via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 25 07:15:02 PDT 2023
steakhal added a comment.
I checked out the code to see how does the Static Analyzer work after this.
I'm impressed that it seems to work.
Do you mind adding my test file to this patch?
`clang/test/Analysis/cxx2b-deducing-this.cpp`:
// RUN: %clang_analyze_cc1 -std=c++2b -verify %s \
// RUN: -analyzer-checker=core,debug.ExprInspection
template <typename T> void clang_analyzer_dump(T);
struct S {
int num;
S *orig;
void a(this auto Self) {
clang_analyzer_dump(&Self); // expected-warning {{&Self}}
clang_analyzer_dump(Self.orig); // expected-warning {{&s}}
clang_analyzer_dump(Self.num); // expected-warning {{5 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{5 S32b}}
Self.num = 1;
clang_analyzer_dump(Self.num); // expected-warning {{1 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{5 S32b}}
}
void b(this auto& Self) {
clang_analyzer_dump(&Self); // expected-warning {{&s}}
clang_analyzer_dump(Self.orig); // expected-warning {{&s}}
clang_analyzer_dump(Self.num); // expected-warning {{5 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{5 S32b}}
Self.num = 2;
clang_analyzer_dump(Self.num); // expected-warning {{2 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{2 S32b}}
}
void c(this S Self) {
clang_analyzer_dump(&Self); // expected-warning {{&Self}}
clang_analyzer_dump(Self.orig); // expected-warning {{&s}}
clang_analyzer_dump(Self.num); // expected-warning {{2 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{2 S32b}}
Self.num = 3;
clang_analyzer_dump(Self.num); // expected-warning {{3 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{2 S32b}}
}
void c(this S Self, int I) {
clang_analyzer_dump(I); // expected-warning {{11 S32b}}
clang_analyzer_dump(&Self); // expected-warning {{&Self}}
clang_analyzer_dump(Self.orig); // expected-warning {{&s}}
clang_analyzer_dump(Self.num); // expected-warning {{2 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{2 S32b}}
Self.num = 4;
clang_analyzer_dump(Self.num); // expected-warning {{4 S32b}}
clang_analyzer_dump(Self.orig->num); // expected-warning {{2 S32b}}
}
};
void top() {
S s = {/*num=*/5, /*orig=*/&s};
s.a();
s.b(); // This call changes 's.num' to 2.
s.c();
s.c(11);
}
Thank you for implementing (deducing) this!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140828/new/
https://reviews.llvm.org/D140828
More information about the llvm-commits
mailing list