summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2017-10-04 16:49:20 +0000
committerJonas Toth <jonas.toth@gmail.com>2017-10-04 16:49:20 +0000
commit5a09996ff70ee0cd533c8d401f3924aee662551f (patch)
tree1eda979223a25702d7602e1af6d760c58a150232 /clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
parent45ff83ce1eb45e786c02c9fb6a5d6b87cbdb3842 (diff)
downloadbcm5719-llvm-5a09996ff70ee0cd533c8d401f3924aee662551f.tar.gz
bcm5719-llvm-5a09996ff70ee0cd533c8d401f3924aee662551f.zip
[clang-tidy] Emit note for variable declaration that are later deleted
This patch introduces a note for variable declaration that are later deleted. Adds FIXME notes for possible automatic type-rewriting positions as well. Reviewed by aaron.ballman Differential: https://reviews.llvm.org/D38411 llvm-svn: 314913
Diffstat (limited to 'clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
index d7841d9d434..ac3d92c98ac 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp
@@ -156,6 +156,13 @@ bool OwningMemoryCheck::handleDeletion(const BoundNodes &Nodes) {
"not marked 'gsl::owner<>'; consider using a "
"smart pointer instead")
<< DeletedVariable->getSourceRange();
+
+ // FIXME: The declaration of the variable that was deleted can be
+ // rewritten.
+ const ValueDecl *Decl = DeletedVariable->getDecl();
+ diag(Decl->getLocStart(), "variable declared here", DiagnosticIDs::Note)
+ << Decl->getSourceRange();
+
return true;
}
return false;
@@ -244,7 +251,9 @@ bool OwningMemoryCheck::handleAssignmentFromNewOwner(const BoundNodes &Nodes) {
"initializing non-owner %0 with a newly created 'gsl::owner<>'")
<< BadOwnerInitialization->getType()
<< BadOwnerInitialization->getSourceRange();
- // FIXME: FixitHint to rewrite the type if possible.
+
+ // FIXME: FixitHint to rewrite the type of the initialized variable
+ // as 'gsl::owner<OriginalType>'
// If the type of the variable was deduced, the wrapping owner typedef is
// eliminated, therefore the check emits a special note for that case.
@@ -277,14 +286,15 @@ bool OwningMemoryCheck::handleReturnValues(const BoundNodes &Nodes) {
// Function return values, that should be owners but aren't.
if (BadReturnType) {
- // The returned value is of type owner, but not the declared return type.
+ // The returned value is a resource or variable that was not annotated with
+ // owner<> and the function return type is not owner<>.
diag(BadReturnType->getLocStart(),
"returning a newly created resource of "
"type %0 or 'gsl::owner<>' from a "
"function whose return type is not 'gsl::owner<>'")
<< Function->getReturnType() << BadReturnType->getSourceRange();
- // The returned value is a resource that was not annotated with owner<> and
- // the function return type is not owner<>.
+
+ // FIXME: Rewrite the return type as 'gsl::owner<OriginalType>'
return true;
}
return false;
OpenPOWER on IntegriCloud