[PATCH] D123655: [clang-tidy] Add portability-std-allocator-const-t check

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 13 11:58:31 PDT 2022


sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LG from my side. It won't catch all cases, but I think it gets the common ones.

Up to you/Louis how best to describe the libc++ behavior.



================
Comment at: clang-tools-extra/test/clang-tidy/checkers/portability-std-allocator-const.cpp:65
+  // CHECK-MESSAGES: [[#@LINE-1]]:26: warning: container
+  my_vector v1;
+
----------------
maybe `using my_vector2 = my_vector;`, with no extra diagnostics


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/portability-std-allocator-const.cpp:76
+void temp() {
+  std::vector<const T> v;
+  // CHECK-MESSAGES: [[#@LINE-1]]:8: warning: container
----------------
This case will always be an error, but isn't diagnosed until you see an instantiation.

If it's important to catch these standalone e.g. when analyzing headers, you could adapt the matcher like:

```
hasUnqualifiedDesugaredType(anyOf(
  recordDecl(...), // current case
  templateSpecializationType( // when dependent, TST is canonical
    templateArgumentCountIs(1), // std::vector<const dependent>
    hasTemplateArgument(0, refersToType(qualType(isConstQualified())))
  )
))
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123655



More information about the cfe-commits mailing list