[PATCH] D36354: [clang-tidy] Implement type-based check for `gsl::owner`
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 8 13:30:57 PDT 2017
aaron.ballman added inline comments.
================
Comment at: test/clang-tidy/cppcoreguidelines-owning-memory.cpp:39
+ return new int(42);
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: returning a 'gsl::owner<>' from a function but not declaring it; return type is 'int *'
+}
----------------
JonasToth wrote:
> aaron.ballman wrote:
> > This diagnostic confuses me -- there's no gsl::owner<> involved anywhere; am I missing something?
> `owner<>` is not involved, but the guidelines say, that `new` must be assigned to an owner.
>
> This is in line with the resource semantics. Everything that creates an resource, that must be released (no RAII available) shall be annotated.
>
> The diagnostic is bad, though.
>
> `Returning a newly created resource from function 'functionname', without declaring it as 'gsl::owner<>'; type is '...'`
Okay, that makes more sense to me. I don't think the name of the function helps all that much in the diagnostic, however. What about:
`"returning a newly created resource of type %0 from a function whose return type is not 'gsl::owner<>'"`
https://reviews.llvm.org/D36354
More information about the cfe-commits
mailing list