Как передать аргумент GslHeader в clang-tidy при использовании параметра -fix?

Мне не удалось найти образец кода для упорядоченной командной строки для исправления следующей ошибки:

[archlinux@thinkpad fizzbuzz]$ clang-tidy fizzbuzz2.cpp -checks=cppcoreguidelines-pro-bounds-constant-array-index
5 warnings generated.
fizzbuzz2.cpp:21:18: warning: do not use array subscript when the index is not an integer constant expression; use gsl::at() instead [cppcoreguidelines-pro-bounds-constant-array-index]
    std::cout << arr[index] << std::endl;
                 ^
Suppressed 4 warnings (4 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
[archlinux@thinkpad fizzbuzz]$ 

Я просто хочу узнать, как я могу исправить это автоматически. Если нет, как мне использовать gsl::at(), чтобы исправить это? В документации clang-tidy говорится следующее:

cppcoreguidelines-pro-bounds-constant-array-index

This check flags all array subscript expressions on static arrays and std::arrays that either do not have a constant integer expression index or are out of bounds (for std::array). For out-of-bounds checking of static arrays, see the -Warray-bounds Clang diagnostic.

This rule is part of the “Bounds safety” profile of the C++ Core Guidelines, see https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Pro-bounds-arrayindex.
Options

GslHeader

    The check can generate fixes after this option has been set to the name of the include file that contains gsl::at(), e.g. “gsl/gsl.h”.

IncludeStyle

    A string specifying which include-style is used, llvm or google. Default is llvm.

Я нашел подпрограмму gsl::at() в <gsl/gsl_util>. Как мне сказать clang-tidy использовать его для исправления моего предупреждения?

Изменить: я посмотрел на строку конфигурации и нашел решение:

На бегу:

clang-tidy fizzbuzz2.cpp -checks=cppcoreguidelines-pro-bounds-constant-array-index -dump-config

У меня есть подсказки по поводу решения

clang-tidy fizzbuzz2.cpp -checks=cppcoreguidelines-pro-bounds-constant-array-index -config="{CheckOptions: [{key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader, value: gsl/gsl_util}]}" -fix


person urmish    schedule 10.08.2018    source источник


Ответы (1)


Изменить: я посмотрел на строку конфигурации и нашел решение:

На бегу:

clang-tidy fizzbuzz2.cpp -checks=cppcoreguidelines-pro-bounds-constant-array-index -dump-config

У меня есть подсказки по поводу решения

clang-tidy fizzbuzz2.cpp -checks=cppcoreguidelines-pro-bounds-constant-array-index -config="{CheckOptions: [{key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader, value: gsl/gsl_util}]}" -fix
person urmish    schedule 10.08.2018