1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "qualify_declval.hpp"
12 AST_MATCHER(clang::UnresolvedLookupExpr
, requiresADL
) { return Node
.requiresADL(); }
13 AST_MATCHER(clang::UnresolvedLookupExpr
, isDeclval
) { return Node
.getName().getAsString() == "declval"; }
17 qualify_declval::qualify_declval(llvm::StringRef name
, clang::tidy::ClangTidyContext
* context
)
18 : clang::tidy::ClangTidyCheck(name
, context
) {}
20 void 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);
25 void 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::");