diff options
| author | Kirill Bobyrev <omtcyfz@gmail.com> | 2016-09-26 06:22:54 +0000 |
|---|---|---|
| committer | Kirill Bobyrev <omtcyfz@gmail.com> | 2016-09-26 06:22:54 +0000 |
| commit | 6c9e06a95c0a6cb3d8a80a3af18332326501e8a8 (patch) | |
| tree | 90334960e33a1817255488b2200232c29958d815 /clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp | |
| parent | d7a5ed414140ff2a7d85cf8613b2b43a16511256 (diff) | |
| download | bcm5719-llvm-6c9e06a95c0a6cb3d8a80a3af18332326501e8a8.tar.gz bcm5719-llvm-6c9e06a95c0a6cb3d8a80a3af18332326501e8a8.zip | |
[clang-tidy] make readability-redundant-smartptr-get report get() usage in conditions
This patch extends clang-tidy's readability-redundant-smartptr-get to produce
warnings for previously unsupported cases:
```
std::unique_ptr<void> ptr;
if (ptr.get())
if (ptr.get() == NULL)
if (ptr.get() != NULL)
```
This is intended to fix https://llvm.org/bugs/show_bug.cgi?id=25804, a bug
report opened by @Eugene.Zelenko.
However, there still are cases not detected by the check. They can be found in
`void Negative()` function defined in
test/clang-tidy/readability-redundant-smartptr-get.cpp.
llvm-svn: 282382
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp')
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp b/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp index 61a36f6dee3..985efc58e42 100644 --- a/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-redundant-smartptr-get.cpp @@ -113,6 +113,37 @@ void Positive() { // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call // CHECK-MESSAGES: i = *PointerWithOverloadedGet().get(); // CHECK-FIXES: i = *PointerWithOverloadedGet(); + + bb = std::unique_ptr<int>().get() == NULL; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call + // CHECK-MESSAGES: bb = std::unique_ptr<int>().get() == NULL; + // CHECK-FIXES: bb = std::unique_ptr<int>() == NULL; + bb = ss->get() == NULL; + // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call + // CHECK-MESSAGES: bb = ss->get() == NULL; + // CHECK-FIXES: bb = *ss == NULL; + + std::unique_ptr<int> x, y; + if (x.get() == nullptr); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call + // CHECK-MESSAGES: if (x.get() == nullptr); + // CHECK-FIXES: if (x == nullptr); + if (nullptr == y.get()); + // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant get() call + // CHECK-MESSAGES: if (nullptr == y.get()); + // CHECK-FIXES: if (nullptr == y); + if (x.get() == NULL); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call + // CHECK-MESSAGES: if (x.get() == NULL); + // CHECK-FIXES: if (x == NULL); + if (NULL == x.get()); + // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call + // CHECK-MESSAGES: if (NULL == x.get()); + // CHECK-FIXES: if (NULL == x); + if (x.get()); + // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call + // CHECK-MESSAGES: if (x.get()); + // CHECK-FIXES: if (x); } void Negative() { @@ -137,7 +168,5 @@ void Negative() { (*Fail2().get()).Do(); int_ptr ip; - bool bb = std::unique_ptr<int>().get() == NULL; - bb = ip.get() == nullptr; - bb = u->get() == NULL; + bool bb = ip.get() == nullptr; } |

