<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55088>55088</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy cppcoreguidelines-pro-bounds-constant-array-index fix is missing the edit to add `#include <gsl/gsl>` if there's an `#if/endif` at the top of the file
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sean-mcmanus
      </td>
    </tr>
</table>

<pre>
    Repro is with clang 14.0.0.

With a --config like `{ Checks: 'cppcoreguidelines-pro-bounds-constant-array-index', CheckOptions: [{key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader, value: '<gsl/gsl>'`.

Repro code is
```
#if defined(_WIN32)
#include <string>
#endif
#include <array>

int func(int i)
{
    std::array<int, 2> v;
    return v[i];
}
```

The clang-tidy fix appears to not be able to add the `#include <gsl/gsl>` if there's a `#if/endif` at the top of the file -- it works when that code is removed.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVU8GOmzAQ_RpzsYjAQEgOHDbZbttLK1WV9lgZewA3jo1sk938fcfANrvSXpIgYzPP780bj1srr80vGJ2lytMXFQYqNDc9zctNhn-SPZLsYRmfY5TTNBXWdKqnWp2Akm1G6gM9DiBOnhQPlLBajKOwDvpJSdDKgE-RP23tZKSPm33gJqTcOX5NlZHwinsIOy4kP8egEDJTVQfkPsE1Lu4m3Xz1-htwCS5yX7ieYM2PFMfea8Ke4lh8iV-2H60uFRFWApZlDaDR5VmWrFAdldBhKpKw3Z_n7z8KRtj-FjZCT0iAaj44Zfoo9RYEI1X3GXQ2cEPOozKBdpMRKBOn6qZSH5YJxZ8PEv3hs1IcERudM2SjF1K8gzoIkzP4sTooUj3-j5H68XOz8_h7gKU50qDklXbqlfJxBO48DZYaG2gLlLca4pJLScOw9McHgx8qv80oVhFxDvAUPHbXiu8Qs9QIITzMVMGO1M5o1EaVNKUq0BfrTti5AxiMIHI9NPR4theQ67EmsinkvtjzJKigoXnn4-7Gmp2jwll5j8c6JwQSU1lt32nZ3OE5mZxuhhDGeD8QHmnxVk7tRtgzLrS-vL2ii78gsAWeMM8JPE6qKtvtkqEpalHuc5nnhdyWbMvrcscLxqGoIOt4XSWat6B9Ey8gYwZe6EyBc-yWRDUsYywrWcWKrMyyDW4XLd-1eS7bnIsdKTM4c6U3MY-NdX3imjmlduo9BrXywd-CHMvYG4BZDvn5FAbrGg_cpGdx5mbyyazfzPn_A_6PdC8">