diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/NoUncountedMembersChecker.cpp @@ -75,7 +75,8 @@ continue; if (auto *MemberCXXRD = MemberType->getPointeeCXXRecordDecl()) { - if (isRefCountable(MemberCXXRD)) + // If we don't see the definition we just don't know. + if (MemberCXXRD->hasDefinition() && isRefCountable(MemberCXXRD)) reportBug(Member, MemberType, MemberCXXRD, RD); } } diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/Checkers/WebKit/uncounted-members-regression-46142.cpp @@ -0,0 +1,9 @@ +// regression test for https://bugs.llvm.org/show_bug.cgi?id=46142 + +// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.WebKitNoUncountedMemberChecker -verify %s +// expected-no-diagnostics + +class ClassWithoutADefinition; +class Foo { + const ClassWithoutADefinition *foo; +};