llvm / llvm/llvm-project

[clang-tidy] Make `modernize-avoid-c-arrays` have an optional fix

Open
#202,346 3 comments 1 reaction 0 assignees View on GitHub
clang-tidy enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently, the clang-tidy documentation states that `modernize-avoid-c-arrays` is ["dangerous to use"](https://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-arrays.html#modernize-avoid-c-arrays):

`fix-it are potentially dangerous in header files and are therefore not emitted right now.`

However, since this feature would be very useful by itself (imagine the amount of boilerplate C++98 style code using c-style arrays, especially for complex types and non-integer literal constant, it gets way harder to refactor this without making mistakes, or create a python script catching all cases, so the most reliable solution is compiler-supported automatic generation of equivalent std::array via clang-tidy), and I would like to utilize it maybe via copying the clang-tidy generated type everywhere else (currently, I understand that checking everything in header files would be very hard to implement for clang-tidy developers, but since there is no good solution for now, something automatically generated which I can then copy-paste would be much better than what we have now).

I propose adding a clang-tidy configuration flag that would allow this option to propose a fix (which is especially useful with IDEs in combination with clangd and clang-tidy)
Thanks.

Contributor guide

Open the contributing guide

Research direction

Start with the clang-tidy modernize-avoid-c-arrays check and its documentation at the linked page, focusing on how fix-its are currently suppressed in header files. Determine where a configuration flag would be documented and handled, then verify that enabling it proposes the intended fix while preserving the existing default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.