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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "qualify_declval.hpp"
10
11namespace {
12AST_MATCHER(clang::UnresolvedLookupExpr, requiresADL) { return Node.requiresADL(); }
13AST_MATCHER(clang::UnresolvedLookupExpr, isDeclval) { return Node.getName().getAsString() == "declval"; }
14} // namespace
15
16namespace libcpp {
17qualify_declval::qualify_declval(llvm::StringRef name, clang::tidy::ClangTidyContext* context)
18 : clang::tidy::ClangTidyCheck(name, context) {}
19
20void qualify_declval::registerMatchers(clang::ast_matchers::MatchFinder* finder) {
21 using namespace clang::ast_matchers;
22 finder->addMatcher(callExpr(has(unresolvedLookupExpr(requiresADL(), isDeclval()))).bind("ADLcall"), this);
23}
24
25void qualify_declval::check(const clang::ast_matchers::MatchFinder::MatchResult& result) {
26 if (const auto* call = result.Nodes.getNodeAs<clang::CallExpr>("ADLcall"); call != nullptr) {
27 diag(call->getBeginLoc(), "declval should be qualified to get better error messages")
28 << clang::FixItHint::CreateInsertion(call->getBeginLoc(), "std::");
29 }
30}
31} // namespace libcpp
32

source code of libcxx/test/tools/clang_tidy_checks/qualify_declval.cpp