[PATCH] D53771: [clang-tidy] Avoid C arrays check

Roman Lebedev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 26 10:29:34 PDT 2018


lebedev.ri created this revision.
lebedev.ri added reviewers: aaron.ballman, JonasToth, alexfh, hokein, xazax.hun.
lebedev.ri added a project: clang-tools-extra.
Herald added subscribers: rnkovacs, mgorny.
lebedev.ri edited the summary of this revision.

PR39224 <https://bugs.llvm.org/show_bug.cgi?id=39224>
As discussed, we can't always do the transform automatically due to that array-to-pointer decay of C array.
In order to detect whether we can do said transform, we'd need to be able to see all usages of said array,
which is, i would say, rather impossible if e.g. it is in the header.
Thus right now no fixit exists.

Also, is `misc` the best place for this check?

Exceptions: `extern "C"` code.

References:

- CPPCG ES.27: Use std::array or stack_array for arrays on the stack <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es27-use-stdarray-or-stack_array-for-arrays-on-the-stack>
- CPPCG SL.con.1: Prefer using STL array or vector instead of a C array <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#slcon1-prefer-using-stl-array-or-vector-instead-of-a-c-array>
- HICPP `4.1.1 Ensure that a function argument does not undergo an array-to-pointer conversion`
- MISRA `5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer`


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53771

Files:
  clang-tidy/misc/AvoidCArraysCheck.cpp
  clang-tidy/misc/AvoidCArraysCheck.h
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-avoid-c-arrays.rst
  test/clang-tidy/misc-avoid-c-arrays.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53771.171315.patch
Type: text/x-patch
Size: 9152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181026/d386bf66/attachment.bin>


More information about the cfe-commits mailing list