[PATCH] Add clang-tidy check to remove redundant .get() calls on smart pointers.

Samuel Benzaquen sbenza at google.com
Wed Mar 26 11:59:02 PDT 2014



================
Comment at: clang-tidy/misc/RedundantSmartptrGet.cpp:56
@@ +55,3 @@
+void RedundantSmartptrGet::check(const MatchFinder::MatchResult &Result) {
+  {
+    // First verify that the types match.
----------------
Alexander Kornienko wrote:
> What's the reason to enclose this in a compound statement?
> If you want to limit visibility of local variables, then it's better to make this a separate function.
Done.

================
Comment at: clang-tidy/misc/RedundantSmartptrGet.cpp:75
@@ +74,3 @@
+
+  const std::string SmartptrText = Lexer::getSourceText(
+      CharSourceRange::getTokenRange(Smartptr->getSourceRange()),
----------------
Alexander Kornienko wrote:
> Why not use StringRef here?
Fixed.

================
Comment at: clang-tidy/misc/RedundantSmartptrGet.cpp:80
@@ +79,3 @@
+  const std::string Replacement =
+      IsPtrToPtr ? (Twine("*") + SmartptrText).str() : SmartptrText;
+  diag(GetCall->getLocStart(), "Redundant get() call on smart pointer.")
----------------
Alexander Kornienko wrote:
> nit: How about Twine(IsPtrToPtr ? "*" : "", SmartptrText).str()? It's bit shorter and seems not to be less clear.
Done.

================
Comment at: test/clang-tidy/redundant-smartptr-get.cpp:44
@@ +43,3 @@
+  std::unique_ptr<Bar>().get()->Do();
+  // CHECK: warning: Redundant get() call on smart pointer. [misc-redundant-smartptr-get]
+
----------------
Alexander Kornienko wrote:
> Maybe add line and column numbers to make the tests more precise?
> // CHECK: :[[@LINE-1]]:<column number>: warning: ...
> 
> I'd also leave the whole error message only once, and abbreviate all other occasions so that they don't exceed the column limit and thus are easier to read.
Done.


http://llvm-reviews.chandlerc.com/D3186



More information about the cfe-commits mailing list