[PATCH] D53025: [clang-tidy] implement new check for const return types.

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 22 08:04:37 PDT 2018


ymandel marked an inline comment as done.
ymandel added inline comments.


================
Comment at: test/clang-tidy/readability-const-value-return.cpp:174
+int **const * n_multiple_ptr();
+int *const & n_pointer_ref();
----------------
aaron.ballman wrote:
> I'd like to see some more complex examples, like:
> ```
> int const foo();
> int const * const foo();
> 
> std::add_const<int> foo();
> 
> template <typename Ty>
> std::add_const<Ty> foo();
> 
> auto foo() -> const int;
> auto foo() -> int const;
> 
> template <typename Ty>
> auto foo() -> std::add_const<Ty>;
> ```
> I'm also very curious to hear how often this triggers on large code bases, especially ones that claim decent const-correctness.
I've added examples along the lines you suggested.  However, the code cannot currently catch the "auto foo() -> type" form, and I couldn't find an easy way to change this. I've noted as much in the comments.

Also, the template version (whether trailing or normal return) does not trigger the matchers at all, from which I surmise that clang doesn't consider the type const qualified when it is not materialized with an actual type. I've noted as much in the comments, but please correct me if I've misunderstood.

Finally, as for triggering: I ran this over Google's C++ codebase and found quite a few hits (10k < X < 100k;  not sure I'm allowed to specify a more precise value for X, but if you need it,  let me know and I'll ask).  I sampled 100 of them and confirmed that all were correct.

I also looked at LLVM and found ~130 hits. I sampled 10 and again found them all correct. I'm happy to post all of the llvm hits if you think that would be helpful.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025





More information about the cfe-commits mailing list