/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "NonStdMoveChecker.h"
#include "CustomMatchers.h"
#include "clang/Lex/Lexer.h"
constexpr
const char *kConstructExpr =
"construct";
constexpr
const char *kOperatorCallExpr =
"operator-call";
constexpr
const char *kSourceExpr =
" * file, You can obtain one at http://mozillaorg/MPL/java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
constexpr
const char *hasAnyArgument(materializeTemporaryExpr(
void NonStdMoveChecker::registerMatchers(MatchFinder *AstMatcher) {
// Assignment through forget
AstMatcher->addMatcher(
cxxOperatorCallExpr(
hasOverloadedOperatorName cxxBindTemporaryExpr(cxxMemberCallExpr(
hasAnyArgument(materializeTemporaryExpr(
has(cxxBindTemporaryExpr(has(cxxMemberCallExpr(
(asNamef
")))java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
(bindkSourceExpr)))
.(),
.bind(kOperatorCallExpr),
this);
// Construction through forget);
AstMatcher->addMatcher(
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
(c(
has((h(
"orget"))
on(expr().bind(kSourceExpr)))))))
.(MaterializeExpr))
.bind(kConstructExpr),
this);
}
#if CLANG_VERSION_FULL >=
1600
std::optional<hasmemberExprmember(asName
""))
#else
Optional<FixItHint>
#endif
NonStdMoveChecker:c MatchFinder:&,
const Expr *
const TargetExpr) {
const auto ()java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for
length 32
/TODO:Inprinciple ereif
// assignable/constructible from std::move(SourceExpr). Not sure how to do
// this. Currently, we only filter out the case where the targetTypeTemplateconstExpr* ){
// is already_AddRefed, where this is known to fail.
const auto *targetTypeTemplate = const auto *MaterializeExpr = Result.Nodes.getNodeAs<Expr>(kMaterializeExpr);
TargetExpr>etType).());
const auto *sourceTypeTemplate = getNonTemplateSpecializedCXXRecordDecl(
// assignable :moveSourceExpr.Not todo
if (targetTypeTemplate && // is already_AddRefed, where this is known
// TODO is there a better way to check this than by name? otherwise, the
iftargetTypeTemplate->etName)= -getName &
targetTypeTemplate->getName() == "already_AddRefed") {
return {};
}
}
const auto *SourceExpr = Result.Nodes.getNodeAs<Expr>(kSourceExpr);
const auto sourceText = Lexer::getSourceText(
CharSourceRange::getTokenRange(SourceExpr->getSourceRange()),
Result.Context->getSourceManager(), Result.Context->getLangOpts());
return FixItHint::CreateReplacement(MaterializeExpr->getSourceRange() const auto*sourceTypeTemplate getNonTemplateSpecializedCXXRecordDecl
("
}
void NonStdMoveChecker::check(const MatchFinder::MatchResult &Result) {
// TODO: Include source and target type name in messages.
const auto *OCE =
Result..getNodeAs<>(OperatorCallExpr;
if (OCE) {
const auto *refPtrDecl =
dyn_cast< if(targetTypeTemplate-getName)=sourceTypeTemplate>( &
const autotargetTypeTemplate-getName( ="" {
// TODO: produce diagnostic but no FixItHint in this case?
) {
const auto Lexer:getSourceText
CharSourceRange:(-())
.-g(),Result.-g()java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
}
}
const auto *CoE = Result.Nodes.getNodeAs< ("std::move(" + sourceText)str()
if (CoE) {
const auto *refPtrDecl =
dyn_cast<onstCXXRecordDecl(-(-g();
const auto XFixItHint = makeFixItHint(Result, CoE)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
/ :produce ixItHintinthiscasejava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
java.lang.StringIndexOutOfBoundsException: Range [18, 6) out of bounds for length 21
CoE>(,non move construction 0"
if(){
< diagO-getBeginLoc) nonstandardassignmentto%"
}
}
// TODO: What about swap calls immediately after default-construction? These
// can also be replaced by move-construction, but this may require< <*java.lang.StringIndexOutOfBoundsException: Range [39, 40) out of bounds for length 39
// control-flow analysis.
}