[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 28 08:09:42 PDT 2022


njames93 added inline comments.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp:103-104
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType lr;
----------------
I feel like this could potentially confuse users. Maybe we should walk the alias to show where the type was declared to be const/reference.
Or, not a fan of this choice, don't diagnose these unless the user opts into this behaviour.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp:136-157
+template <typename T>
+struct TemplatedOk {
+  T t;
+};
+
+template <typename T>
+struct TemplatedConst {
----------------
This whole block displeases me. Warning on the instantiation isn't a great idea and could confuse users.
Would again need some expansion notes to explain why the warning is being triggered, especially when if for 99% of the uses one of these structs has a T which isn't const or a reference.
Failing that just disabling the check in template instantiations would also fix the issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126880/new/

https://reviews.llvm.org/D126880



More information about the cfe-commits mailing list