================
@@ -112,16 +155,18 @@ void ContainerDataPointerCheck::check(const
MatchFinder::MatchResult &Result) {
if (NeedsParens)
ReplacementText = "(" + ReplacementText + ")";
- if (CE->getType()->isPointerType())
- ReplacementText += "->data()";
- else
- ReplacementText += ".data()";
+ ReplacementText += CE->getType()->isPointerType() ? "->" : ".";
+ ReplacementText += UseCStr ? "c_str()" : "data()";
+ llvm::StringRef Description = UseCStr
+ ? "'c_str' should be used for accessing "
+ "the data pointer instead of taking "
+ "the address of the 0-th element"
+ : "'data' should be used for accessing the
"
+ "data pointer instead of taking "
+ "the address of the 0-th element";
const FixItHint Hint =
- FixItHint::CreateReplacement(UO->getSourceRange(), ReplacementText);
- diag(UO->getBeginLoc(),
- "'data' should be used for accessing the data pointer instead of taking
"
- "the address of the 0-th element")
- << Hint;
+ FixItHint::CreateReplacement(ReplacementRange, ReplacementText);
+ diag(UO->getBeginLoc(), Description) << Hint;
----------------
5chmidti wrote:
Please use the select syntax:
```c++
"'%select{data|c_str}0' should be used...")
<< UseCStr
```
https://github.com/llvm/llvm-project/pull/190590
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits