[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays
Chris Cotter via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 1 14:25:06 PDT 2023
ccotter marked an inline comment as done.
ccotter added inline comments.
================
Comment at: clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp:170-172
+ char init4[] = "abcdef";
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+ // CHECK-FIXES: std::array<char, 7> init4 = { "abcdef" };
----------------
PiotrZSL wrote:
> I don't think this check should replace those strings, simply that could break code, image someone is using this later as an argument to some function that expect pointer.
> For strings std::string_view would be better alternative (at least add a bypass for this).
> And all those changes are not safe if variable is used for pointer arithmetic.
>
>
The logic I implemented should fix pointer arithmetic (e.g., `str + 1` is replaced by `str.begin() + 1`. I have tests for this for `int[]`, but added more for `char[]`. string_view is not appropriate conversion here since the arrays may be modified etc.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145138/new/
https://reviews.llvm.org/D145138
More information about the cfe-commits
mailing list