Was using clang 17.0.6 and stumbled onto this inconsistency:
clang-query
accepts the following and outputs correct expected match.
clang-query> match declaratorDecl(unless(isExpansionInSystemHeader()), hasType(qualType(hasDeclaration(classTemplateSpecializationDecl(hasDescendant(hasDeclaration(cxxRecordDecl(hasName(“::std::thread”)))))))))
Match #1:
…/clang-tidy-extensions/src/test/no-std-thread.cpp:41:1: note: “root” binds here
41 | std::variant< std::thread > VariantThread {};
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 match.
However, when compiled in a clang-tidy plugin, the outcome is an error.
/opt/clang170/include/clang/ASTMatchers/ASTMatchersInternal.h:1498:3: note: template argument deduction/substitution failed:
…/clang-tidy-extensions/src/clang-tidy/NoStdThreadCheck.cpp:75:194: note: ‘clang::ast_matchers::internal::PolymorphicMatcher<clang::ast_matchers::internal::HasDeclarationMatcher, void(clang::ast_matchers::internal::TypeList<clang::CallExpr, clang::CXXConstructExpr, clang::CXXNewExpr, clang::DeclRefExpr, clang::EnumType, clang::ElaboratedType, clang::InjectedClassNameType, clang::LabelStmt, clang::AddrLabelExpr, clang::MemberExpr, clang::QualType, clang::RecordType, clang::TagType, clang::TemplateSpecializationType, clang::TemplateTypeParmType, clang::TypedefType, clang::UnresolvedUsingType, clang::ObjCIvarRefExpr>), clang::ast_matchers::internal::Matcherclang::Decl >’ is not derived from ‘const clang::ast_matchers::internal::MapAnyOfHelper<T …>’
declaratorDecl(unless(isExpansionInSystemHeader()), hasType(qualType(hasDeclaration(classTemplateSpecializationDecl(hasDescendant(hasDeclaration(cxxRecordDecl(hasName(“::std::thread”))))))))).bind(“template-vars”),
As the Getting Involved — Extra Clang Tools 20.0.0git documentation guide suggests using clang-query
to prototype matchers, this difference caught me offguard.
The equivalent that works in the plugin is actually
declaratorDecl(unless(isExpansionInSystemHeader()), hasType(qualType(hasDeclaration(classTemplateSpecializationDecl(hasDescendant(cxxRecordDecl(hasName(“::std::thread”))))))))
which removes the hasDeclaration
after the hasDescendant
.
Clang-query doesn’t match this one, though.
clang-query> match declaratorDecl(unless(isExpansionInSystemHeader()), hasType(qualType(hasDeclaration(classTemplateSpecializationDecl(hasDescendant(cxxRecordDecl(hasName(“::std::thread”))))))))
0 matches.
Can anything be done regarding this? Similar surprises occured here: Matcher working in clang-query, but not in LibTooling - #3 by Stephen_Kelly