summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2015-09-29 13:12:21 +0000
committerAaron Ballman <aaron@aaronballman.com>2015-09-29 13:12:21 +0000
commitde34985caae79ce7d125cd55fa634e74aa04427d (patch)
tree5741ab14b526f6f51be6cc15ed32518c29305563 /clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp
parent4a7436fd82063de5e4cad83da0a9cfc1f77711b6 (diff)
downloadbcm5719-llvm-de34985caae79ce7d125cd55fa634e74aa04427d.tar.gz
bcm5719-llvm-de34985caae79ce7d125cd55fa634e74aa04427d.zip
Adding a checker (misc-new-delete-overloads) that detects mismatched overloads of operator new and operator delete. Corresponds to the CERT C++ secure coding rule: https://www.securecoding.cert.org/confluence/display/cplusplus/DCL54-CPP.+Overload+allocation+and+deallocation+functions+as+a+pair+in+the+same+scope
llvm-svn: 248791
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp b/clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp
new file mode 100644
index 00000000000..992c2fdf9ed
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp
@@ -0,0 +1,18 @@
+// RUN: %python %S/check_clang_tidy.py %s misc-new-delete-overloads %t -- -std=c++14 -fsized-deallocation
+
+struct S {
+ // CHECK-MESSAGES: :[[@LINE+1]]:8: warning: declaration of 'operator delete' has no matching declaration of 'operator new' at the same scope [misc-new-delete-overloads]
+ void operator delete(void *ptr, size_t) noexcept; // not a placement delete
+};
+
+struct T {
+ // Because we have enabled sized deallocations explicitly, this new/delete
+ // pair matches.
+ void *operator new(size_t size) noexcept;
+ void operator delete(void *ptr, size_t) noexcept; // ok because sized deallocation is enabled
+};
+
+// While we're here, check that global operator delete with no operator new
+// is also matched.
+// CHECK-MESSAGES: :[[@LINE+1]]:6: warning: declaration of 'operator delete' has no matching declaration of 'operator new' at the same scope
+void operator delete(void *ptr) noexcept;
OpenPOWER on IntegriCloud