Juan Besa 4d259de2ae
[clang-tidy] Add IgnoreAliasing option to readability-qualified-auto check (#147060)
`readability-qualified-auto` check currently looks at the unsugared
type, skipping any typedefs, to determine if the variable is a
pointer-type. This may not be the desired behaviour, in particular when
the type depends on compilation flags.
For example

```
 #if CONDITION
      using Handler = int *;
  #else
      using Handler = uint64_t;
  #endif
```

A more common example is some implementations of `std::array` use
pointers as iterators.

This introduces the IgnoreAliasing option so that
`readability-qualified-auto` does not look beyond typedefs.

---------

Co-authored-by: juanbesa <juanbesa@devvm33299.lla0.facebook.com>
Co-authored-by: Kazu Hirata <kazu@google.com>
Co-authored-by: EugeneZelenko <eugene.zelenko@gmail.com>
Co-authored-by: Baranov Victor <bar.victor.2002@gmail.com>
2025-07-28 18:20:02 +03:00

41 lines
1.5 KiB
C++

//===--- QualifiedAutoCheck.h - clang-tidy ----------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_QUALIFIEDAUTOCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_QUALIFIEDAUTOCHECK_H
#include "../ClangTidyCheck.h"
namespace clang::tidy::readability {
/// Finds variables declared as auto that could be declared as:
/// 'auto*' or 'const auto *' and reference variables declared as:
/// 'const auto &'.
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/qualified-auto.html
class QualifiedAutoCheck : public ClangTidyCheck {
public:
QualifiedAutoCheck(StringRef Name, ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
private:
const bool AddConstToQualified;
const std::vector<StringRef> AllowedTypes;
const bool IgnoreAliasing;
};
} // namespace clang::tidy::readability
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_QUALIFIEDAUTOCHECK_H