Skip to content

Commit 80f11cb

Browse files
localspookdyung
authored andcommitted
release/22.x: Backport workarounds for certain addMatcher overloads ignoring traversal kind
1 parent 8ac0a12 commit 80f11cb

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ void TypeTraitsCheck::registerMatchers(MatchFinder *Finder) {
195195
.bind(Bind),
196196
this);
197197
}
198-
Finder->addMatcher(typeLoc(isType()).bind(Bind), this);
198+
Finder->addMatcher(
199+
traverse(TK_IgnoreUnlessSpelledInSource, typeLoc(isType()).bind(Bind)),
200+
this);
199201
}
200202

201203
static bool isNamedDeclInStdTraitsSet(const NamedDecl *ND,

clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace clang::tidy::readability {
1919

2020
void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
2121
Finder->addMatcher(
22-
typeLoc(unless(hasAncestor(decl(isInstantiated())))).bind("typeLoc"),
22+
traverse(TK_IgnoreUnlessSpelledInSource, typeLoc().bind("typeLoc")),
2323
this);
2424

2525
if (!getLangOpts().CPlusPlus20)

clang-tools-extra/test/clang-tidy/checkers/modernize/type-traits.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,17 @@ struct ImplicitlyInstantiatedConstructor {
150150
const ImplicitlyInstantiatedConstructor<int> ImplicitInstantiation(std::remove_reference<int>::type(123));
151151
// CHECK-MESSAGES: :[[@LINE-1]]:68: warning: use c++14 style type templates
152152
// CHECK-FIXES: const ImplicitlyInstantiatedConstructor<int> ImplicitInstantiation(std::remove_reference_t<int>(123));
153+
154+
#if __cplusplus >= 202002L
155+
156+
template <typename T>
157+
struct S {
158+
typename std::remove_reference<T>::type a; // NOLINT
159+
};
160+
161+
void f() {
162+
auto [a] = S<int>{};
163+
[&] { a; }; // This used to cause a false positive.
164+
}
165+
166+
#endif // __cplusplus >= 202002L

0 commit comments

Comments
 (0)