[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / clang-tools-extra / clang-tidy / cppcoreguidelines / AvoidConstOrRefDataMembersCheck.cpp
blobb22fa94663d584beedbe092017dfa7059b430c89
1 //===--- AvoidConstOrRefDataMembersCheck.cpp - clang-tidy -----------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "AvoidConstOrRefDataMembersCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 using namespace clang::ast_matchers;
15 namespace clang::tidy::cppcoreguidelines {
16 namespace {
18 AST_MATCHER(FieldDecl, isMemberOfLambda) {
19 return Node.getParent()->isLambda();
22 } // namespace
24 void AvoidConstOrRefDataMembersCheck::registerMatchers(MatchFinder *Finder) {
25 Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
26 hasType(hasCanonicalType(referenceType())))
27 .bind("ref"),
28 this);
29 Finder->addMatcher(fieldDecl(unless(isMemberOfLambda()),
30 hasType(qualType(isConstQualified())))
31 .bind("const"),
32 this);
35 void AvoidConstOrRefDataMembersCheck::check(
36 const MatchFinder::MatchResult &Result) {
37 if (const auto *MatchedDecl = Result.Nodes.getNodeAs<FieldDecl>("ref"))
38 diag(MatchedDecl->getLocation(), "member %0 of type %1 is a reference")
39 << MatchedDecl << MatchedDecl->getType();
40 if (const auto *MatchedDecl = Result.Nodes.getNodeAs<FieldDecl>("const"))
41 diag(MatchedDecl->getLocation(), "member %0 of type %1 is const qualified")
42 << MatchedDecl << MatchedDecl->getType();
45 } // namespace clang::tidy::cppcoreguidelines