[clang-tools-extra] r337710 - [clang-tidy] fix PR36489 - respect deduced pointer types from auto as well

Jonas Toth via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 23 10:13:06 PDT 2018


Author: jonastoth
Date: Mon Jul 23 10:13:06 2018
New Revision: 337710

URL: http://llvm.org/viewvc/llvm-project?rev=337710&view=rev
Log:
[clang-tidy] fix PR36489 - respect deduced pointer types from auto as well

Summary:
The cppcoreguidelines-pro-bounds-pointer-arithmetic warns on all occassion where
pointer arithmetic is used, but does not check values where the pointer types
is deduced via ``auto``. This patch adjusts this behaviour and solved
PR36489.

Reviewers: alexfh, aaron.ballman, hokein, ilya-biryukov

Reviewed By: alexfh, aaron.ballman

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

Differential Revision: https://reviews.llvm.org/D48717

Modified:
    clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp?rev=337710&r1=337709&r2=337710&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-pointer-arithmetic.cpp Mon Jul 23 10:13:06 2018
@@ -85,5 +85,32 @@ void okay() {
 
   auto diff = p - q; // OK, result is arithmetic
 
-  for(int ii : a) ; // OK, pointer arithmetic generated by compiler
+  for (int ii : a)
+    ; // OK, pointer arithmetic generated by compiler
+}
+
+// Fix PR36207
+namespace std {
+template <typename CharT>
+struct char_traits {};
+
+template <typename T>
+struct allocator {};
+
+template <typename CharT,
+          typename Traits = char_traits<CharT>,
+          typename Allocator = allocator<CharT>>
+class basic_string {};
+
+template <class CharT, class Traits, class Alloc>
+basic_string<CharT, Traits, Alloc> operator+(const basic_string<CharT, Traits, Alloc> &lhs,
+                                             const CharT *rhs) {}
+
+using string = basic_string<char>;
+} // namespace std
+
+std::string str_generated() {}
+
+void problematic_addition() {
+  std::string status = str_generated() + " is not found";
 }




More information about the cfe-commits mailing list