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

    <tr>
        <th>Summary</th>
        <td>
            static_assert cannot prevent OOM caused by numeric overflow
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ingomueller-net
      </td>
    </tr>
</table>

<pre>
    Consider the following snippet:

```cpp
// Compile with: clang-15 -std=c++14 test.cpp
#include <utility>

int main(int, char**) {
  static constexpr std::size_t kA = 2;
  static constexpr std::size_t kB = 1;
  static_assert(kA <= kB, "Should fail");                     // Prints an error on std::out but compilation continues
  static constexpr std::size_t kMinusOne = kB - kA;           // Produces an overflow
  using IndexSequence = std::make_index_sequence<kMinusOne>;  // Makes clang++ run out of memory
}
```

The `static_assert` fails; however, compilation continues, presumably for diagnostics. The subsequent code produces a numeric overflow, which causes a huge type to be created (namely `std::make_index_sequence<18446744073709551615>`), which makes the compiler run until it runs out of memory.

The problem is two-fold:
1. The compiler should not run out of memory but give up before that. In many setups, continuing until the kernel kills the compiler may freeze the machine.
2. It does not seem possible to prevent the compiler from doing this mistake since it continues to compile even after the failed assert. (Admittedly, diagnostics after the first error are helpful, so not sure if that has a fix.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVUlv6zYQ_jXyZWBBm7eDDo7dAD0EKfB6DyhqZLGmSJVLHL9f3yFlO3byULQGvYjkLN9CutHtud5pZUWLBlyP0Gkp9UmoA1glxhFdUm6TbJ9k189lNg0-jpeZ4pkG7PQwColwEq6nGOCSqcM8X8DcujYp9zwpnmjkFTi0Lr0LL4Xi0rcISbnzTkjhzkn5231RoRwMTKikWNPPpNgB75lJim0cG0hWT9NGAOuYExw4YXL4MRqI1bc0rPiJbw6OW6qzhyIp_0fMU4zJv8W8MWvRUEfrmHYXdh2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