================
@@ -0,0 +1,113 @@
+// RUN: %check_clang_tidy -std=c++17-or-later %s 
bugprone-smart-ptr-initialization %t -- -- -I %S/../modernize/Inputs/smart-ptr
+
+#include "shared_ptr.h"
+#include "unique_ptr.h"
+
+namespace std {
+template<typename T>
+  struct remove_reference
+  { using type = T; };
+
+template<typename T>
+  struct remove_reference<T&>
+  { using type = T; };
+
+template<typename T>
+  struct remove_reference<T&&>
+  { using type = T; };
+
+template<typename T>
+  constexpr typename std::remove_reference<T>::type&&
+  move(T&& t) noexcept;
+}
+
+
+struct A {
+  int x;
+};
+
+A arr[10];
+
+void test_shared_ptr_constructor() {
+  std::shared_ptr<A[]> a(arr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: passing a raw pointer 'arr' to 
std::shared_ptr<A[]> constructor may cause double deletion 
[bugprone-smart-ptr-initialization]
+}
+
+void test_stack_variable() {
+  int x[10] = {5};
+  std::shared_ptr<int[]> ptr(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: passing a raw pointer 'x' to 
std::shared_ptr<int[]> constructor may cause double deletion 
[bugprone-smart-ptr-initialization]
+}
+
+// Should trigger for member variables
+struct S {
+  int member[10];
+  void test() {
+    std::shared_ptr<int[]> ptr(member);
+    // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: passing a raw pointer 
'this->member' to std::shared_ptr<int[]> constructor may cause double deletion 
[bugprone-smart-ptr-initialization]
----------------
denzor200 wrote:

Changed

https://github.com/llvm/llvm-project/pull/181570
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to