namespace tidy {
namespace misc {
-namespace {
-// FIXME: it would be good to make a list that is also user-configurable so that
-// users can add their own elements to the list. However, it may require some
-// extra thought since POSIX types and FILE types are usable in different ways.
-bool isPOSIXTypeName(StringRef ClassName) {
- static const char *const TypeNames[] = {
- "::pthread_cond_t",
- "::pthread_mutex_t",
- "pthread_cond_t",
- "pthread_mutex_t"
- };
- return std::binary_search(std::begin(TypeNames), std::end(TypeNames),
- ClassName);
-}
-
-bool isFILETypeName(StringRef ClassName) {
- static const char *const TypeNames[] = {
- "::FILE",
- "FILE",
- "std::FILE"
- };
- return std::binary_search(std::begin(TypeNames), std::end(TypeNames),
- ClassName);
-}
-
-AST_MATCHER(NamedDecl, isFILEType) {
- return isFILETypeName(Node.getQualifiedNameAsString());
-}
-
-AST_MATCHER(NamedDecl, isPOSIXType) {
- return isPOSIXTypeName(Node.getQualifiedNameAsString());
-}
-} // namespace
-
void NonCopyableObjectsCheck::registerMatchers(MatchFinder *Finder) {
// There are two ways to get into trouble with objects like FILE *:
// dereferencing the pointer type to be a non-pointer type, and declaring
// non-pointer variable or data member of the type, but it is not reasonable
// to dereference a pointer to the type, or declare a parameter of non-pointer
// type.
- auto BadFILEType = hasType(namedDecl(isFILEType()).bind("type_decl"));
- auto BadPOSIXType = hasType(namedDecl(isPOSIXType()).bind("type_decl"));
+ // FIXME: it would be good to make a list that is also user-configurable so
+ // that users can add their own elements to the list. However, it may require
+ // some extra thought since POSIX types and FILE types are usable in different
+ // ways.
+
+ auto BadFILEType = hasType(
+ namedDecl(hasAnyName("::FILE", "FILE", "std::FILE")).bind("type_decl"));
+ auto BadPOSIXType =
+ hasType(namedDecl(hasAnyName("::pthread_cond_t", "::pthread_mutex_t",
+ "pthread_cond_t", "pthread_mutex_t"))
+ .bind("type_decl"));
auto BadEitherType = anyOf(BadFILEType, BadPOSIXType);
Finder->addMatcher(