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

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy 15.0.3 SEGFAULT during token parsing on macos-12
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          CramBL
      </td>
    </tr>
</table>

<pre>
    No idea what's happening here but the clang-tidy crash says `Error running '/Users/runner/llvm/bin/clang-tidy': PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.` so here I am.

## Stack dump + link to CI
The crash happens on macos-12 in CI and not in any Ubuntu or Windows builds, link to macos job:
https://github.com/CramBL/mtgo-collection-manager/actions/runs/6763154657/job/18379945737.

Stack dump is too large for an issue so here's a link:  [raw log - ctrl+f PLEASE takes you to the stack dump](https://pipelinesghubeus25.actions.githubusercontent.com/tygirYM1qxOzrhqLVBX7sg5gMMFN1q1EARz4vRefpCXmMUNl7m/_apis/pipelines/1/runs/1662/signedlogcontent/13?urlExpires=2023-11-05T19%3A10%3A44.0884746Z&urlSigningMethod=HMACV1&urlSignature=DLul%2F7L%2Fd%2BXXOL3ucXYKQznn7VdsfzrrQfaBn0Kd3cU%3D)

## More context
There's several CI runs where the same thing happens.

It appears to happen while clang-tidy is parsing this function `io_util::save_with_timestamp`. [Here's the implementation of that function as of the CI run that produced the logs linked to above](https://github.com/CramBL/mtgo-collection-manager/blob/save-card-price-history/mtgoparser/include/mtgoparser/io.hpp#L91).

Here's a version of that function without preprocessor macros that produced the same clang-tidy crash:
```c++
[[nodiscard]] inline auto save_with_timestamp(const auto &buf, const fs::path &fpath, const auto &ext)
  -> outcome::result<fs::path, std::string>
{
  try {
 // If the path is not to the current directory
    if (fpath.has_parent_path()) {
      // Create directories if they don't exist
      fs::create_directories(fpath.parent_path());
    }
 // Get the current time
    const auto now = std::chrono::system_clock::now();

    // Convert to a timestamp in UTC and %Y-%m-%dT%H:%M:%SZ which is ISO 8601
    // using formatter: https://en.cppreference.com/w/cpp/chrono/system_clock/formatter
 std::string tmp_iso8601_timestamp = std::vformat("{:%FT%TZ}", std::make_format_args(now));

    // It has sub-second precision, so remove the decimal point and everything after it, then add a 'Z' to indicate UTC
    std::string now_utc_iso8601_timestamp = tmp_iso8601_timestamp.substr(0, tmp_iso8601_timestamp.find('.')) + 'Z';
 // Erase-remove idiom to remove colons from timestamp as they are not allowed in Windows file names
    now_utc_iso8601_timestamp.erase(
 std::remove(now_utc_iso8601_timestamp.begin(), now_utc_iso8601_timestamp.end(), ':'),
 now_utc_iso8601_timestamp.end());

    std::string final_fname = fmt::format("{}_{}.{}", fpath.stem().string(), now_utc_iso8601_timestamp, ext);

    fs::path fpath_with_time =
      fpath.has_parent_path() ? fpath.parent_path() / final_fname : boost::implicit_cast<fs::path>(final_fname);

    // Open the file
 std::ofstream file(fpath_with_time, std::ios::binary | std::ios::out);

    if (file.bad()) {
      return outcome::failure(fmt::format("Bad operation during opening of file: {}", fpath_with_time.string()));
    }

    if (file.is_open()) {
 // Write the buffer to the file
      file.write(buf.data(), static_cast<std::streamsize>(buf.size()));
      // Close the file
 file.close();
    } else {
      return outcome::failure(fmt::format("Expected file to be open: {}", fpath_with_time.string()));
    }


    // Return the file name
    return outcome::success(fpath_with_time);

  } catch (const std::exception &e) {
    return outcome::failure(fmt::format("Failed to save file from path: {}, err: {}", fpath.string(), e.what()));
 }
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWF1z4rgS_TXKiwoXlgHDQx4ChJ3UJjN3J8nszLxQstzG2tiSR5JDMr_-VksGAyFz725tKoXB-upz-vSHza2VGwVwScZzMl5e8NaV2lwuDK_ntxeZzl8vP2oqc-B0W3JHWGppyZsGlFQbWoIBmrWOuhKoqLjaDJzMX6kw3JbU8ldLyWR4bYw21LTKryEsJWz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