[PATCH] D156031: [clang-tidy] Ignore implcit casts in cppcoreguidelines-owning-memory
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 22 12:26:57 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b5b75bfd4d4: [clang-tidy] Ignore implcit casts in cppcoreguidelines-owning-memory (authored by PiotrZSL).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156031/new/
https://reviews.llvm.org/D156031
Files:
clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/owning-memory.cpp
@@ -382,3 +382,16 @@
template_function(IntOwner1); // Ok, but not actually ok, since type deduction removes owner
template_function(stack_ptr1); // Bad, but type deduction gets it wrong
}
+
+namespace PR63994 {
+ struct A {
+ virtual ~A() {}
+ };
+
+ struct B : public A {};
+
+ A* foo(int x) {
+ return new B;
+ // CHECK-NOTES: [[@LINE-1]]:5: warning: returning a newly created resource of type 'A *' or 'gsl::owner<>' from a function whose return type is not 'gsl::owner<>'
+ }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -330,6 +330,10 @@
to emit warnings only on classes that are copyable/movable, as required by the
corresponding rule.
+- Improved :doc:`cppcoreguidelines-owning-memory
+ <clang-tidy/checks/cppcoreguidelines/owning-memory>` check now finds more
+ issues, especially those related to implicit casts.
+
- Deprecated C.48 enforcement from :doc:`cppcoreguidelines-prefer-member-initializer
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>`. Please use
:doc:`cppcoreguidelines-use-default-member-init
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.h
@@ -37,6 +37,9 @@
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ std::optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
bool handleDeletion(const ast_matchers::BoundNodes &Nodes);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156031.543221.patch
Type: text/x-patch
Size: 2206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230722/f3ae9025/attachment.bin>
More information about the cfe-commits
mailing list