llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.4k stars 11.73k forks source link

[clang-tidy] False positive modernize-avoid-c-arrays for function parameters #108053

Open chrchr-github opened 4 weeks ago

chrchr-github commented 4 weeks ago
#include <iostream>

void f(const char a[]) {
    std::cout << a;
}

void g(const char* p) {
    f("abc");
    f(p);
}
<source>:3:14: warning: do not declare C-style arrays, use std::array<> instead [modernize-avoid-c-arrays]
    3 | void f(const char a[]) {
      |              ^

Clearly std::array cannot be used here.

chrchr-github commented 4 weeks ago

Related: https://github.com/llvm/llvm-project/issues/60411

HerrCai0907 commented 3 weeks ago

I don't think it is a false positive. f should receive a c-str instead of an array of char, though the diagnose message is not correct. You should correct it with const char* instead if array<char, ?>.

HerrCai0907 commented 3 weeks ago

IgnoreStringArrayIfNeededMatcher may help you to ignore this warning.