void Positive() { BarPtr u; // CHECK: BarPtr u; BarPtr().get()->Do(); // CHECK: BarPtr()->Do(); u.get()->ConstDo(); // CHECK: u->ConstDo(); Bar& b = *BarPtr().get(); // CHECK: Bar& b = *BarPtr(); (*BarPtr().get()).ConstDo(); // CHECK: (*BarPtr()).ConstDo(); BarPtr* up; (*up->get()).Do(); // CHECK: (**up).Do(); int_ptr ip; int i = *ip.get(); // CHECK: int i = *ip; std::unique_ptr<int> uu; std::shared_ptr<double> *ss; bool bb = uu.get() == nullptr; // CHECK: bool bb = uu == nullptr; bb = nullptr != ss->get(); // CHECK: bb = nullptr != *ss; }
void Positive() { BarPtr u; // CHECK-FIXES: BarPtr u; BarPtr().get()->Do(); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. [readability-redundant-smartptr-get] // CHECK-MESSAGES: BarPtr().get()->Do(); // CHECK-FIXES: BarPtr()->Do(); u.get()->ConstDo(); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: u.get()->ConstDo(); // CHECK-FIXES: u->ConstDo(); Bar& b = *BarPtr().get(); // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: Bar& b = *BarPtr().get(); // CHECK-FIXES: Bar& b = *BarPtr(); Bar& b2 = *std::unique_ptr<Bar>().get(); // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: Bar& b2 = *std::unique_ptr<Bar>().get(); // CHECK-FIXES: Bar& b2 = *std::unique_ptr<Bar>(); (*BarPtr().get()).ConstDo(); // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: (*BarPtr().get()).ConstDo(); // CHECK-FIXES: (*BarPtr()).ConstDo(); (*std::unique_ptr<Bar>().get()).ConstDo(); // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: (*std::unique_ptr<Bar>().get()).ConstDo(); // CHECK-FIXES: (*std::unique_ptr<Bar>()).ConstDo(); std::unique_ptr<Bar>* up; (*up->get()).Do(); // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: (*up->get()).Do(); // CHECK-FIXES: (**up).Do(); int_ptr ip; int i = *ip.get(); // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: int i = *ip.get(); // CHECK-FIXES: int i = *ip; std::unique_ptr<int> uu; std::shared_ptr<double> *ss; bool bb = uu.get() == nullptr; // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: uu.get() == nullptr; // CHECK-FIXES: bool bb = uu == nullptr; bb = nullptr != ss->get(); // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: Redundant get() call on smart pointer. // CHECK-MESSAGES: nullptr != ss->get(); // CHECK-FIXES: bb = nullptr != *ss; }