| 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 |
|
| 11 |
namespace { |
| 12 |
AST_MATCHER(clang::UnresolvedLookupExpr, requiresADL) { return Node.requiresADL(); } |
| 13 |
AST_MATCHER(clang::UnresolvedLookupExpr, isDeclval) { return Node.getName().getAsString() == "declval"; } |
| 14 |
} // namespace |
| 15 |
|
| 16 |
namespace libcpp { |
| 17 |
qualify_declval::qualify_declval(llvm::StringRef name, clang::tidy::ClangTidyContext* context) |
| 18 |
: clang::tidy::ClangTidyCheck(name, context) {} |
| 19 |
|
| 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); |
| 23 |
} |
| 24 |
|
| 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::"); |
| 29 |
} |
| 30 |
} |
| 31 |
} // namespace libcpp |