@@ -136,14 +136,27 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
136136
137137 auto IsBoundToType = refersToType (equalsBoundNode (" type" ));
138138 auto UnlessFunctionType = unless (hasUnqualifiedDesugaredType (functionType ()));
139- auto IsAutoDeducedToPointer = [](const std::vector<StringRef> &AllowedTypes,
140- const auto &...InnerMatchers ) {
141- return autoType (hasDeducedType (
142- hasUnqualifiedDesugaredType (pointerType (pointee (InnerMatchers...))),
143- unless (hasUnqualifiedType (
144- matchers::matchesAnyListedTypeName (AllowedTypes, false ))),
145- unless (pointerType (pointee (hasUnqualifiedType (
146- matchers::matchesAnyListedTypeName (AllowedTypes, false )))))));
139+ auto RespectOpaqueTypes = this ->RespectOpaqueTypes ;
140+ auto IsAutoDeducedToPointer = [&RespectOpaqueTypes](
141+ const std::vector<StringRef> &AllowedTypes,
142+ const auto &...InnerMatchers ) {
143+ if (!RespectOpaqueTypes) {
144+ return autoType (hasDeducedType (
145+ hasUnqualifiedDesugaredType (pointerType (pointee (InnerMatchers...))),
146+ unless (hasUnqualifiedType (
147+ matchers::matchesAnyListedTypeName (AllowedTypes, false ))),
148+ unless (pointerType (pointee (hasUnqualifiedType (
149+ matchers::matchesAnyListedTypeName (AllowedTypes, false )))))));
150+ } else {
151+ return autoType (hasDeducedType (
152+ anyOf (qualType (pointerType (pointee (InnerMatchers...))),
153+ qualType (substTemplateTypeParmType (hasReplacementType (
154+ pointerType (pointee (InnerMatchers...)))))),
155+ unless (hasUnqualifiedType (
156+ matchers::matchesAnyListedTypeName (AllowedTypes, false ))),
157+ unless (pointerType (pointee (hasUnqualifiedType (
158+ matchers::matchesAnyListedTypeName (AllowedTypes, false )))))));
159+ }
147160 };
148161
149162 Finder->addMatcher (
@@ -176,21 +189,6 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
176189
177190void QualifiedAutoCheck::check (const MatchFinder::MatchResult &Result) {
178191 if (const auto *Var = Result.Nodes .getNodeAs <VarDecl>(" auto" )) {
179- if (RespectOpaqueTypes) {
180- QualType DeducedType =
181- Var->getType ()->getContainedAutoType ()->getDeducedType ();
182-
183- // Remove one sugar if the type if part of a template
184- if (llvm::isa<SubstTemplateTypeParmType>(DeducedType)) {
185- DeducedType =
186- DeducedType->getLocallyUnqualifiedSingleStepDesugaredType ();
187- }
188-
189- if (!isa<PointerType>(DeducedType)) {
190- return ;
191- }
192- }
193-
194192 SourceRange TypeSpecifier;
195193 if (std::optional<SourceRange> TypeSpec =
196194 getTypeSpecifierLocation (Var, Result)) {
0 commit comments