[clang-tools-extra] [clang-tidy] offer option to check sugared types in avoid-c-arrays check (PR #131468)
St. Muench via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 25 05:19:28 PDT 2025
stmuench wrote:
> Example:
>
> ```
> #include <type_traits>
>
> template <typename T, bool = std::is_same_v<int, T>> void f(T &&value) {}
>
> void test() {
> int t[10];
> f(t);
> }
> ```
>
> ```
> /root/1.cpp:3:50: warning: do not declare C-style arrays, use 'std::array' instead [cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays]
> 3 | template <typename T, bool = std::is_same_v<int, T>> void f(T &&value) {}
> | ^
> /root/1.cpp:6:3: warning: do not declare C-style arrays, use 'std::array' instead [cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays]
> 6 | int t[10];
> | ^
> ```
>
> In above code check is executed in template instance even that TK_IgnoreUnlessSpelledInSource is set. With your change it will be even worst.
>
> Thing is that if check would properly handled implicit code then "template parameters" would never be catch. At the end check should point places in code where actually arrays are defined, otherwise if you would put array into type alias, then you would get warning in every place that type alias is used, and that's stupid as there is only one place where such array can be fixed, and that is a definition of that type alias.
@PiotrZSL in https://github.com/llvm/llvm-project/pull/132924 I added a proposal for not diagnosing array types within implicit instantiations of a template. Kindly have a look and provide feedback in case you are interested.
https://github.com/llvm/llvm-project/pull/131468
More information about the cfe-commits
mailing list