brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 5fa4f09 Raw
55 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H11 12#include "../ClangTidyCheck.h"13#include "llvm/ADT/SmallPtrSet.h"14#include <set>15#include <vector>16 17namespace clang::tidy::bugprone {18 19/// Checks if an unused forward declaration is in a wrong namespace.20///21/// The check inspects all unused forward declarations and checks if there is22/// any declaration/definition with the same name, which could indicate23/// that the forward declaration is potentially in a wrong namespace.24///25/// \code26///   namespace na { struct A; }27///   namespace nb { struct A {} };28///   nb::A a;29///   // warning : no definition found for 'A', but a definition with the same30///   name 'A' found in another namespace 'nb::'31/// \endcode32///33/// This check can only generate warnings, but it can't suggest fixes at this34/// point.35///36/// For the user-facing documentation see:37/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/forward-declaration-namespace.html38class ForwardDeclarationNamespaceCheck : public ClangTidyCheck {39public:40  ForwardDeclarationNamespaceCheck(StringRef Name, ClangTidyContext *Context)41      : ClangTidyCheck(Name, Context) {}42  void registerMatchers(ast_matchers::MatchFinder *Finder) override;43  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;44  void onEndOfTranslationUnit() override;45 46private:47  llvm::StringMap<std::vector<const CXXRecordDecl *>> DeclNameToDefinitions;48  llvm::StringMap<std::vector<const CXXRecordDecl *>> DeclNameToDeclarations;49  llvm::SmallPtrSet<const Type *, 16> FriendTypes;50};51 52} // namespace clang::tidy::bugprone53 54#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FORWARDDECLARATIONNAMESPACECHECK_H55