Use std::nothrow for the only new expression

Ideally we'd use `std::make_shared`, but it has insufficient compiler
support for array types
This commit is contained in:
Rangi42
2025-08-02 22:52:20 -04:00
parent 5a7ffd19b0
commit 543b7fa6c2

View File

@@ -11,6 +11,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#include <new> // nothrow
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -340,7 +341,7 @@ void LexerState::setFileAsNextState(std::string const &filePath, bool updateStat
// Read the entire file for better performance // Read the entire file for better performance
// Ideally we'd use C++20 `auto ptr = std::make_shared<char[]>(size)`, // Ideally we'd use C++20 `auto ptr = std::make_shared<char[]>(size)`,
// but it has insufficient compiler support // but it has insufficient compiler support
auto ptr = std::shared_ptr<char[]>(new char[size]); auto ptr = std::shared_ptr<char[]>(new (std::nothrow) char[size]);
if (std::ifstream fs(path, std::ios::binary); !fs) { if (std::ifstream fs(path, std::ios::binary); !fs) {
// LCOV_EXCL_START // LCOV_EXCL_START