diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-09-29 13:12:21 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-09-29 13:12:21 +0000 |
commit | de34985caae79ce7d125cd55fa634e74aa04427d (patch) | |
tree | 5741ab14b526f6f51be6cc15ed32518c29305563 /clang-tools-extra/test/clang-tidy/misc-new-delete-overloads-sized-dealloc.cpp | |
parent | 4a7436fd82063de5e4cad83da0a9cfc1f77711b6 (diff) | |
download | bcm5719-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.cpp | 18 |
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; |