================ @@ -0,0 +1,72 @@ +//===--- NlohmannJsonExplicitConversionsCheck.cpp - clang-tidy ------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "NlohmannJsonExplicitConversionsCheck.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::modernize { + +void NlohmannJsonExplicitConversionsCheck::registerMatchers( + MatchFinder *Finder) { + auto Matcher = + cxxMemberCallExpr( + on(expr().bind("arg")), + callee(cxxConversionDecl(ofClass(hasName("nlohmann::basic_json"))) + .bind("conversionDecl"))) + .bind("conversionCall"); + Finder->addMatcher(Matcher, this); +} + +void NlohmannJsonExplicitConversionsCheck::check( + const MatchFinder::MatchResult &Result) { + const auto *Decl = + Result.Nodes.getNodeAs<CXXConversionDecl>("conversionDecl"); + const auto *Call = + Result.Nodes.getNodeAs<CXXMemberCallExpr>("conversionCall"); + const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg"); + + const QualType DestinationType = Decl->getConversionType(); + std::string DestinationTypeStr = + DestinationType.getAsString(Result.Context->getPrintingPolicy()); + if (DestinationTypeStr == "std::basic_string<char>") + DestinationTypeStr = "std::string"; ---------------- mikecrowe wrote:
Thanks for the review. As far as I can tell, the library doesn't support implicit conversion to `std::wstring` or `std::string_view` but I will double check with the author. https://github.com/llvm/llvm-project/pull/126425 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits