Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Add Clang C++ warning to suggest making non-virtual method const #21980

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR21981
Status REOPENED
Importance P enhancement
Reported by Eugene Zelenko (eugene.zelenko@gmail.com)
Reported on 2014-12-19 11:52:02 -0800
Last modified on 2018-07-23 13:20:42 -0700
Version unspecified
Hardware All All
CC alexfh@google.com, development@jonas-toth.eu, djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org, tomtheengineer@gmail.com, trass3r@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

Hi!

I think will be great to have warning which will suggest to make non-vuirtual method const if doesn't modify object's state and/or call only other const methods.

Eugene.

Quuxplusone commented 8 years ago

Implemented in r279507.

Quuxplusone commented 8 years ago

Sorry, closed by mistake. r279507 check constness of parameters.

Quuxplusone commented 7 years ago
Would need to be transitive though to be useful.
If you have a pointer as member and call non-const methods on it the parent
method shouldn't be const.
Quuxplusone commented 6 years ago

There is utility functionality in clang-tidy that can in principle determine if a method is used as const and that usecase was specificially mentioned.

See https://reviews.llvm.org/D45444 for a first version using this utility function, in principle it could be used to analyze the this-pointer in methods.