[clang] [webkit.NoUncountedMemberChecker] Warn a raw pointer member in a template instantiation (PR #240100)
Ryosuke Niwa via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 7 22:46:40 PST 2026
https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/240100
Right now, classes like WTF::Vector<T*> results in a warning in the declaration of Vector.
This is problematic because then all unsafe uses of Vector emit their warnings at Vector's member declaration rather than where the template is instantiated with an unsafe type.
This PR changes WebKit checkers so that we look for a unsafe template argument so that a warning will be emitted at where a template is instantiated.
Co-authored with Claude.
rdar://173775767
>From c9c1594aa104ec2e12f2db468c2c82dffce84125 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa <rniwa at webkit.org>
Date: Sat, 7 Nov 2026 22:27:14 -0800
Subject: [PATCH] [webkit.NoUncountedMemberChecker] Warn a raw pointer member
in a template instantiation
Right now, classes like WTF::Vector<T*> results in a warning in the declaration of Vector.
This is problematic because then all unsafe uses of Vector emit their warnings at Vector's
member declaration rather than where the template is instantiated with an unsafe type.
This PR changes WebKit checkers so that we look for a unsafe template argument so that
a warning will be emitted at where a template is instantiated.
Co-authored with Claude.
rdar://173775767
---
.../WebKit/RawPtrRefMemberChecker.cpp | 170 ++++++++++++++++--
.../Checkers/WebKit/unchecked-members.cpp | 6 +-
.../Checkers/WebKit/uncounted-members.cpp | 124 ++++++++++++-
.../Checkers/WebKit/unretained-members-arc.mm | 4 +-
.../Checkers/WebKit/unretained-members.mm | 14 +-
5 files changed, 293 insertions(+), 25 deletions(-)
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
index 8b0ac3e4f2177e..5e20153c39a7e5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefMemberChecker.cpp
@@ -32,6 +32,11 @@ class RawPtrRefMemberChecker
BugType Bug;
mutable BugReporter *BR;
mutable llvm::DenseSet<const ObjCIvarDecl *> IvarDeclsToIgnore;
+ // Maps a template instantiation to the enclosing template instantiation
+ // whose instantiation caused it.
+ mutable llvm::DenseMap<const Decl *, const Decl *> InstantiationCauses;
+ // Template instantiations referenced by template definitions themselves.
+ mutable llvm::DenseSet<const Decl *> NonDependentUses;
protected:
const std::unique_ptr<PtrRefSafetyModel> Model;
@@ -49,12 +54,20 @@ class RawPtrRefMemberChecker
void checkASTDecl(const TranslationUnitDecl *TUD, AnalysisManager &MGR,
BugReporter &BRArg) const {
BR = &BRArg;
+ InstantiationCauses.clear();
+ NonDependentUses.clear();
// The calls to checkAST* from AnalysisConsumer don't
// visit template instantiations or lambda classes. We
// want to visit those, so we make our own RecursiveASTVisitor.
struct LocalVisitor : ConstDynamicRecursiveASTVisitor {
const RawPtrRefMemberChecker *Checker;
+ // Template instantiations are checked after the traversal so that we
+ // know which enclosing template instantiation caused each of them.
+ llvm::SmallVector<const CXXRecordDecl *> Instantiations;
+ // The enclosing classes and functions of the node being visited.
+ llvm::SmallVector<const Decl *> Contexts;
+
explicit LocalVisitor(const RawPtrRefMemberChecker *Checker)
: Checker(Checker) {
assert(Checker);
@@ -62,6 +75,16 @@ class RawPtrRefMemberChecker
ShouldVisitImplicitCode = false;
}
+ bool TraverseDecl(const Decl *D) override {
+ bool IsContext = isa_and_nonnull<CXXRecordDecl, FunctionDecl>(D);
+ if (IsContext)
+ Contexts.push_back(D);
+ bool Result = ConstDynamicRecursiveASTVisitor::TraverseDecl(D);
+ if (IsContext)
+ Contexts.pop_back();
+ return Result;
+ }
+
bool VisitTypedefDecl(const TypedefDecl *TD) override {
if (auto *RTC = Checker->Model->retainTypeChecker())
RTC->visitTypedef(TD);
@@ -69,7 +92,11 @@ class RawPtrRefMemberChecker
}
bool VisitRecordDecl(const RecordDecl *RD) override {
- Checker->visitRecordDecl(RD);
+ auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
+ if (CXXRD && isInstantiation(CXXRD))
+ Instantiations.push_back(CXXRD);
+ else
+ Checker->visitRecordDecl(RD);
return true;
}
@@ -77,23 +104,141 @@ class RawPtrRefMemberChecker
Checker->visitObjCDecl(CD);
return true;
}
+
+ bool VisitTypeLoc(TypeLoc TL) override {
+ if (!TL.getType().isNull())
+ Checker->recordUse(TL.getType()->getAsCXXRecordDecl(), Contexts);
+ return true;
+ }
+
+ bool VisitDeclRefExpr(const DeclRefExpr *E) override {
+ Checker->recordUse(E->getDecl(), Contexts);
+ return true;
+ }
+
+ bool VisitMemberExpr(const MemberExpr *E) override {
+ Checker->recordUse(E->getMemberDecl(), Contexts);
+ return true;
+ }
};
LocalVisitor visitor(this);
if (auto *RTC = Model->retainTypeChecker())
RTC->visitTranslationUnitDecl(TUD);
visitor.TraverseDecl(TUD);
+ for (auto *RD : visitor.Instantiations)
+ visitRecordDecl(RD);
}
void visitRecordDecl(const RecordDecl *RD) const {
if (shouldSkipDecl(RD))
return;
- for (auto *Member : RD->fields())
+ const CXXRecordDecl *Pattern = nullptr;
+ SourceLocation InstantiationLoc;
+ if (auto *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
+ if (isInstantiation(CXXRD)) {
+ Pattern = CXXRD->getTemplateInstantiationPattern();
+ InstantiationLoc = getReportLocation(CXXRD);
+ }
+ }
+
+ for (auto *Member : RD->fields()) {
+ if (Pattern) {
+ // Members whose type doesn't depend on template parameters are
+ // diagnosed in the template definition itself.
+ if (!isDependentInPattern(Member, Pattern))
+ continue;
+ if (InstantiationLoc.isValid()) {
+ visitMember(Member, RD, InstantiationLoc);
+ continue;
+ }
+ }
visitMember(Member, RD);
+ }
+ }
+
+ static bool isDependentInPattern(const FieldDecl *Member,
+ const CXXRecordDecl *Pattern) {
+ if (!Pattern || !Member->getDeclName())
+ return true;
+ for (auto *Found : Pattern->lookup(Member->getDeclName())) {
+ if (auto *PatternField = dyn_cast<FieldDecl>(Found))
+ return PatternField->getType()->isDependentType();
+ }
+ return true;
+ }
+
+ static bool isInstantiation(const Decl *D) {
+ if (auto *RD = dyn_cast<CXXRecordDecl>(D))
+ return isTemplateInstantiation(RD->getTemplateSpecializationKind());
+ if (auto *FD = dyn_cast<FunctionDecl>(D))
+ return isTemplateInstantiation(FD->getTemplateSpecializationKind());
+ return false;
+ }
+
+ static const Decl *getInstantiationPattern(const Decl *D) {
+ if (auto *RD = dyn_cast<CXXRecordDecl>(D))
+ return RD->getTemplateInstantiationPattern();
+ if (auto *FD = dyn_cast<FunctionDecl>(D))
+ return FD->getTemplateInstantiationPattern();
+ return nullptr;
+ }
+
+ static SourceLocation getPointOfInstantiation(const Decl *D) {
+ if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(D))
+ return Spec->getPointOfInstantiation();
+ if (auto *RD = dyn_cast<CXXRecordDecl>(D)) {
+ if (auto *Info = RD->getMemberSpecializationInfo())
+ return Info->getPointOfInstantiation();
+ }
+ if (auto *FD = dyn_cast<FunctionDecl>(D))
+ return FD->getPointOfInstantiation();
+ return SourceLocation();
+ }
+
+ // Records that Used is referenced from the innermost template instantiation
+ // or template definition in Contexts.
+ void recordUse(const Decl *Used, ArrayRef<const Decl *> Contexts) const {
+ if (!Used || !isInstantiation(Used))
+ return;
+ for (auto *Context : llvm::reverse(Contexts)) {
+ if (Context == Used)
+ return;
+ if (isInstantiation(Context)) {
+ // If Used was instantiated from within the definition of the template
+ // Context was instantiated from, Context caused its instantiation.
+ auto *Pattern = getInstantiationPattern(Context);
+ auto &SM = BR->getSourceManager();
+ auto Loc = getPointOfInstantiation(Used);
+ if (Pattern && Loc.isValid() &&
+ SM.isPointWithin(Loc, Pattern->getBeginLoc(), Pattern->getEndLoc()))
+ InstantiationCauses.try_emplace(Used, Context);
+ return;
+ }
+ if (cast<DeclContext>(Context)->isDependentContext()) {
+ // The template definition itself refers to this instantiation.
+ NonDependentUses.insert(Used);
+ return;
+ }
+ }
+ }
+
+ // Returns where the outermost template instantiation which (transitively)
+ // caused D to be instantiated is instantiated.
+ SourceLocation getReportLocation(const Decl *D) const {
+ llvm::SmallPtrSet<const Decl *, 4> Visited;
+ while (Visited.insert(D).second && !NonDependentUses.contains(D)) {
+ auto It = InstantiationCauses.find(D);
+ if (It == InstantiationCauses.end())
+ break;
+ D = It->second;
+ }
+ return getPointOfInstantiation(D);
}
- void visitMember(const FieldDecl *Member, const RecordDecl *RD) const {
+ void visitMember(const FieldDecl *Member, const RecordDecl *RD,
+ SourceLocation ReportLoc = SourceLocation()) const {
auto QT = Member->getType();
const Type *MemberType = QT.getTypePtrOrNull();
@@ -111,9 +256,9 @@ class RawPtrRefMemberChecker
return;
if (auto *MemberCXXRD = MemberType->getPointeeCXXRecordDecl())
- reportBug(Member, MemberType, MemberCXXRD, RD);
+ reportBug(Member, MemberType, MemberCXXRD, RD, ReportLoc);
else if (auto *ObjCDecl = getObjCDeclFromObjCPtr(MemberType))
- reportBug(Member, MemberType, ObjCDecl, RD);
+ reportBug(Member, MemberType, ObjCDecl, RD, ReportLoc);
}
void visitObjCDecl(const ObjCContainerDecl *CD) const {
@@ -265,8 +410,8 @@ class RawPtrRefMemberChecker
template <typename DeclType, typename PointeeType, typename ParentDeclType>
void reportBug(const DeclType *Member, const Type *MemberType,
- const PointeeType *Pointee,
- const ParentDeclType *ClassCXXRD) const {
+ const PointeeType *Pointee, const ParentDeclType *ClassCXXRD,
+ SourceLocation ReportLoc = SourceLocation()) const {
assert(Member);
assert(MemberType);
assert(Pointee);
@@ -296,10 +441,15 @@ class RawPtrRefMemberChecker
} else
printQuotedQualifiedName(Os, Pointee);
- PathDiagnosticLocation BSLoc(Member->getSourceRange().getBegin(),
- BR->getSourceManager());
+ // Members of template instantiations are reported where the template is
+ // instantiated since the template definition itself may be fine.
+ bool IsInstantiation = ReportLoc.isValid();
+ if (!IsInstantiation)
+ ReportLoc = Member->getSourceRange().getBegin();
+ PathDiagnosticLocation BSLoc(ReportLoc, BR->getSourceManager());
auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
- Report->addRange(Member->getSourceRange());
+ if (!IsInstantiation)
+ Report->addRange(Member->getSourceRange());
if (auto *EnclosingCtx = Member->getDeclContext())
Report->setDeclWithIssue(Decl::castFromDeclContext(EnclosingCtx));
BR->emitReport(std::move(Report));
diff --git a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
index 48f9f2119de2b1..cc760567d042b3 100644
--- a/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/unchecked-members.cpp
@@ -27,10 +27,10 @@ namespace members {
template <typename S>
struct FooTmpl {
S* e;
-// expected-warning at -1{{Member variable 'e' (of 'members::FooTmpl<CheckedObj>') is a raw pointer to CheckedPtr-capable type 'CheckedObj'}}
};
void forceTmplToInstantiate(FooTmpl<CheckedObj>) { }
+ // expected-warning at -1{{Member variable 'e' (of 'members::FooTmpl<CheckedObj>') is a raw pointer to CheckedPtr-capable type 'CheckedObj'}}
} // namespace members
@@ -46,10 +46,10 @@ namespace unions {
template<class T>
union FooTmpl {
T* a;
- // expected-warning at -1{{Member variable 'a' (of 'unions::FooTmpl<CheckedObj>') is a raw pointer to CheckedPtr-capable type 'CheckedObj'}}
};
void forceTmplToInstantiate(FooTmpl<CheckedObj>) { }
+ // expected-warning at -1{{Member variable 'a' (of 'unions::FooTmpl<CheckedObj>') is a raw pointer to CheckedPtr-capable type 'CheckedObj'}}
} // namespace unions
@@ -72,9 +72,9 @@ namespace ptr_to_ptr_to_checked_ptr_capable {
template <typename T>
struct TemplateList {
T** elements;
- // expected-warning at -1{{Member variable 'elements' (of 'ptr_to_ptr_to_checked_ptr_capable::TemplateList<CheckedObj>') contains a raw pointer to CheckedPtr-capable type 'CheckedObj'}}
};
TemplateList<CheckedObj> list;
+ // expected-warning at -1{{Member variable 'elements' (of 'ptr_to_ptr_to_checked_ptr_capable::TemplateList<CheckedObj>') contains a raw pointer to CheckedPtr-capable type 'CheckedObj'}}
struct SafeList {
CheckedPtr<CheckedObj>* elements;
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp b/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
index 4da8818f0fc9ae..2baa5b9bb7f342 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-members.cpp
@@ -25,10 +25,10 @@ namespace members {
template<class T>
struct FooTmpl {
T* a;
-// expected-warning at -1{{Member variable 'a' (of 'members::FooTmpl<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
};
void forceTmplToInstantiate(FooTmpl<RefCountable>) {}
+ // expected-warning at -1{{Member variable 'a' (of 'members::FooTmpl<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
struct [[clang::suppress]] FooSuppressed {
private:
@@ -47,10 +47,10 @@ namespace unions {
template<class T>
union FooTmpl {
T* a;
- // expected-warning at -1{{Member variable 'a' (of 'unions::FooTmpl<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
};
void forceTmplToInstantiate(FooTmpl<RefCountable>) {}
+ // expected-warning at -1{{Member variable 'a' (of 'unions::FooTmpl<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
} // unions
namespace ignore_system_header {
@@ -90,12 +90,130 @@ namespace ptr_to_ptr_to_ref_counted {
template <typename T>
struct TemplateList {
T** elements;
- // expected-warning at -1{{Member variable 'elements' (of 'ptr_to_ptr_to_ref_counted::TemplateList<RefCountable>') contains a raw pointer to RefPtr-capable type 'RefCountable'}}
};
TemplateList<RefCountable> list;
+ // expected-warning at -1{{Member variable 'elements' (of 'ptr_to_ptr_to_ref_counted::TemplateList<RefCountable>') contains a raw pointer to RefPtr-capable type 'RefCountable'}}
struct SafeList {
RefPtr<RefCountable>* elements;
};
} // namespace ptr_to_ptr_to_ref_counted
+
+namespace template_instantiation {
+
+ template <typename T>
+ struct Holder {
+ T* dependent;
+ RefCountable* nonDependent;
+ // expected-warning at -1{{Member variable 'nonDependent' (of 'template_instantiation::Holder') is a raw pointer to RefPtr-capable type 'RefCountable'}}
+ };
+
+ Holder<int> intHolder;
+ Holder<RefCountable> refCountableHolder;
+ // expected-warning at -1{{Member variable 'dependent' (of 'template_instantiation::Holder<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
+
+ struct OtherRefCountable {
+ void ref() const;
+ void deref() const;
+ };
+ Holder<OtherRefCountable> otherHolder;
+ // expected-warning at -1{{Member variable 'dependent' (of 'template_instantiation::Holder<template_instantiation::OtherRefCountable>') is a raw pointer to RefPtr-capable type 'template_instantiation::OtherRefCountable'}}
+
+ template <typename T>
+ struct Outer {
+ struct Inner {
+ T* ptr;
+ };
+ Inner inner;
+ };
+ Outer<RefCountable> outer;
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::Outer<RefCountable>::Inner') is a raw pointer to RefPtr-capable type 'RefCountable'}}
+
+ template <typename T>
+ struct ExplicitlyInstantiated {
+ T* ptr;
+ };
+ template struct ExplicitlyInstantiated<RefCountable>;
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::ExplicitlyInstantiated<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
+
+ template <typename T>
+ struct Specialized {
+ T* ptr;
+ };
+ template <>
+ struct Specialized<RefCountable> {
+ RefCountable* ptr;
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::Specialized<RefCountable>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
+ };
+ Specialized<RefCountable> specialized;
+
+ template <typename T>
+ struct Partial {
+ T value;
+ };
+ template <typename T>
+ struct Partial<T*> {
+ T* ptr;
+ };
+ Partial<RefCountable*> partial;
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::Partial<RefCountable *>') is a raw pointer to RefPtr-capable type 'RefCountable'}}
+
+ struct Nested {
+ void ref() const;
+ void deref() const;
+ };
+
+ template <typename T>
+ struct Inner {
+ T* ptr;
+ };
+
+ template <typename T>
+ struct Middle {
+ Inner<T> inner;
+ };
+
+ template <typename T>
+ struct Top {
+ Middle<T> middle;
+ };
+
+ Top<Nested> top;
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::Inner<template_instantiation::Nested>') is a raw pointer to RefPtr-capable type 'template_instantiation::Nested'}}
+
+ struct UsedInFunction {
+ void ref() const;
+ void deref() const;
+ };
+
+ template <typename T>
+ void useInner() {
+ Inner<T> inner;
+ }
+
+ template <typename T>
+ void callUseInner() {
+ useInner<T>();
+ }
+
+ void callUseInnerWithUsedInFunction() {
+ callUseInner<UsedInFunction>();
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::Inner<template_instantiation::UsedInFunction>') is a raw pointer to RefPtr-capable type 'template_instantiation::UsedInFunction'}}
+ }
+
+ struct NonDependentlyUsed {
+ void ref() const;
+ void deref() const;
+ };
+
+ template <typename T>
+ struct NonDependent {
+ Inner<NonDependentlyUsed> inner;
+ // expected-warning at -1{{Member variable 'ptr' (of 'template_instantiation::Inner<template_instantiation::NonDependentlyUsed>') is a raw pointer to RefPtr-capable type 'template_instantiation::NonDependentlyUsed'}}
+ };
+
+ NonDependent<int> nonDependentInt;
+ NonDependent<char> nonDependentChar;
+
+} // namespace template_instantiation
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members-arc.mm b/clang/test/Analysis/Checkers/WebKit/unretained-members-arc.mm
index ca70b75fc75573..d62d62d177976f 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-members-arc.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-members-arc.mm
@@ -35,11 +35,11 @@
struct FooTmpl {
T* x;
S y;
-// expected-warning at -1{{Member variable 'y' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
R z;
};
void forceTmplToInstantiate(FooTmpl<SomeObj, CFMutableArrayRef, dispatch_queue_t>) {}
+ // expected-warning at -1{{Member variable 'y' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
struct [[clang::suppress]] FooSuppressed {
private:
@@ -59,10 +59,10 @@ void forceTmplToInstantiate(FooTmpl<SomeObj, CFMutableArrayRef, dispatch_queue_t
struct TemplateList {
T* elements1;
S* elements2;
- // expected-warning at -1{{Member variable 'elements2' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type '__CFArray'}}
R* elements3;
};
TemplateList<SomeObj, CFMutableArrayRef, dispatch_queue_t> list;
+ // expected-warning at -1{{Member variable 'elements2' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type '__CFArray'}}
struct SafeList {
RetainPtr<SomeObj>* elements1;
diff --git a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
index 51c9b7851d96d3..139d41a3bac2c1 100644
--- a/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
+++ b/clang/test/Analysis/Checkers/WebKit/unretained-members.mm
@@ -38,14 +38,14 @@
template<class T, class S, class R>
struct FooTmpl {
T* a;
-// expected-warning at -1{{Member variable 'a' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
S b;
-// expected-warning at -1{{Member variable 'b' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
R c;
-// expected-warning at -1{{Member variable 'c' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
};
void forceTmplToInstantiate(FooTmpl<SomeObj, CFMutableArrayRef, dispatch_queue_t>) {}
+ // expected-warning at -1{{Member variable 'a' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
+ // expected-warning at -2{{Member variable 'b' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
+ // expected-warning at -3{{Member variable 'c' (of 'members::FooTmpl<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') is a raw pointer to RetainPtr-capable type}}
struct [[clang::suppress]] FooSuppressed {
private:
@@ -69,10 +69,10 @@ void forceTmplToInstantiate(FooTmpl<SomeObj, CFMutableArrayRef, dispatch_queue_t
template<class T>
union FooTempl {
T* a;
- // expected-warning at -1{{Member variable 'a' (of 'unions::FooTempl<SomeObj>') is a raw pointer to RetainPtr-capable type 'SomeObj'}}
};
void forceTmplToInstantiate(FooTempl<SomeObj>) {}
+ // expected-warning at -1{{Member variable 'a' (of 'unions::FooTempl<SomeObj>') is a raw pointer to RetainPtr-capable type 'SomeObj'}}
}
namespace ptr_to_ptr_to_retained {
@@ -89,13 +89,13 @@ void forceTmplToInstantiate(FooTempl<SomeObj>) {}
template <typename T, typename S, typename R>
struct TemplateList {
T** elements1;
- // expected-warning at -1{{Member variable 'elements1' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type 'SomeObj'}}
S* elements2;
- // expected-warning at -1{{Member variable 'elements2' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type '__CFArray'}}
R* elements3;
- // expected-warning at -1{{Member variable 'elements3' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type 'NSObject'}}
};
TemplateList<SomeObj, CFMutableArrayRef, dispatch_queue_t> list;
+ // expected-warning at -1{{Member variable 'elements1' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type 'SomeObj'}}
+ // expected-warning at -2{{Member variable 'elements2' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type '__CFArray'}}
+ // expected-warning at -3{{Member variable 'elements3' (of 'ptr_to_ptr_to_retained::TemplateList<SomeObj, __CFArray *, NSObject<OS_dispatch_queue> *>') contains a raw pointer to RetainPtr-capable type 'NSObject'}}
struct SafeList {
RetainPtr<SomeObj>* elements1;
More information about the cfe-commits
mailing list