[PATCH] D52552: [clang-tidy] Flag Classes Inheriting From Structs

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 26 09:18:27 PDT 2018


aaron.ballman added a comment.

This strikes me as likely being a very chatty diagnostic. For instance, it will trigger on harmless code that uses empty base class optimization (in addition to other concerns pointed out by @lebedev.ri). It seems like the real concern here is unintentional information disclosure, but I don't see a good heuristic for determining that something is "unintentional" or not. I'd be curious to know how frequently this triggers on some large C++ code bases.



================
Comment at: docs/clang-tidy/checks/misc-class-inherit-from-struct.rst:6-10
+Finds instances of classes inheriting from structs. Structs are meant for 
+storing data and are often used to maintain C compatibility. Having a class
+inherit from them can lead to confusion with what type of object is being 
+dealt with. Additionally, the default public nature of struct members can 
+lead to unintentional exposure of members.
----------------
I don't agree with the predicate here -- structs aren't just used for C compatibility (look at <type_traits> as an example). They're also useful when all members need to be public, which is exactly the situation you claim may be unintentional.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52552





More information about the cfe-commits mailing list