Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ void ContainerDataPointerCheck::check(const MatchFinder::MatchResult &Result) {
Lexer::getSourceText(CharSourceRange::getTokenRange(SrcRange),
*Result.SourceManager, getLangOpts())};

if (!isa<DeclRefExpr, ArraySubscriptExpr, CXXOperatorCallExpr, CallExpr,
MemberExpr>(CE))
const auto *OpCall = dyn_cast<CXXOperatorCallExpr>(CE);
bool NeedsParens =
OpCall ? (OpCall->getOperator() != OO_Subscript)
: !isa<DeclRefExpr, MemberExpr, ArraySubscriptExpr, CallExpr>(CE);
if (NeedsParens)
ReplacementText = "(" + ReplacementText + ")";

if (CE->getType()->isPointerType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ template <typename T>
struct enable_if<true, T> {
typedef T type;
};

template <typename T>
struct unique_ptr {
T &operator*() const;
T *operator->() const;
};
}

template <typename T>
Expand Down Expand Up @@ -144,3 +150,9 @@ int *r() {
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
// CHECK-FIXES: return holder.v.data();
}

void s(std::unique_ptr<std::vector<unsigned char>> p) {
f(&(*p)[0]);
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'data' should be used for accessing the data pointer instead of taking the address of the 0-th element [readability-container-data-pointer]
// CHECK-FIXES: f((*p).data());
}