diff options
Diffstat (limited to '')
| -rw-r--r-- | src/CMakeLists.txt | 6 | ||||
| -rw-r--r-- | src/common/file_util.h | 2 | ||||
| -rw-r--r-- | src/common/misc.cpp | 15 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 71efbb40d..29c6ffc67 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt | |||
| @@ -32,7 +32,6 @@ if (MSVC) | |||
| 32 | # /Zc:inline - Let codegen omit inline functions in object files | 32 | # /Zc:inline - Let codegen omit inline functions in object files |
| 33 | # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null | 33 | # /Zc:throwingNew - Let codegen assume `operator new` (without std::nothrow) will never return null |
| 34 | add_compile_options( | 34 | add_compile_options( |
| 35 | /W3 | ||
| 36 | /MP | 35 | /MP |
| 37 | /Zi | 36 | /Zi |
| 38 | /Zo | 37 | /Zo |
| @@ -43,6 +42,10 @@ if (MSVC) | |||
| 43 | /Zc:externConstexpr | 42 | /Zc:externConstexpr |
| 44 | /Zc:inline | 43 | /Zc:inline |
| 45 | /Zc:throwingNew | 44 | /Zc:throwingNew |
| 45 | |||
| 46 | # Warnings | ||
| 47 | /W3 | ||
| 48 | /we4834 # Discarding return value of function with 'nodiscard' attribute | ||
| 46 | ) | 49 | ) |
| 47 | 50 | ||
| 48 | # /GS- - No stack buffer overflow checks | 51 | # /GS- - No stack buffer overflow checks |
| @@ -56,6 +59,7 @@ else() | |||
| 56 | -Werror=implicit-fallthrough | 59 | -Werror=implicit-fallthrough |
| 57 | -Werror=missing-declarations | 60 | -Werror=missing-declarations |
| 58 | -Werror=reorder | 61 | -Werror=reorder |
| 62 | -Werror=unused-result | ||
| 59 | -Wextra | 63 | -Wextra |
| 60 | -Wmissing-declarations | 64 | -Wmissing-declarations |
| 61 | -Wno-attributes | 65 | -Wno-attributes |
diff --git a/src/common/file_util.h b/src/common/file_util.h index 8b587320f..840cde2a6 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -232,7 +232,7 @@ public: | |||
| 232 | 232 | ||
| 233 | void Swap(IOFile& other) noexcept; | 233 | void Swap(IOFile& other) noexcept; |
| 234 | 234 | ||
| 235 | [[nodiscard]] bool Open(const std::string& filename, const char openmode[], int flags = 0); | 235 | bool Open(const std::string& filename, const char openmode[], int flags = 0); |
| 236 | bool Close(); | 236 | bool Close(); |
| 237 | 237 | ||
| 238 | template <typename T> | 238 | template <typename T> |
diff --git a/src/common/misc.cpp b/src/common/misc.cpp index 68cb86cd1..1d5393597 100644 --- a/src/common/misc.cpp +++ b/src/common/misc.cpp | |||
| @@ -16,16 +16,23 @@ | |||
| 16 | // Call directly after the command or use the error num. | 16 | // Call directly after the command or use the error num. |
| 17 | // This function might change the error code. | 17 | // This function might change the error code. |
| 18 | std::string GetLastErrorMsg() { | 18 | std::string GetLastErrorMsg() { |
| 19 | static const std::size_t buff_size = 255; | 19 | static constexpr std::size_t buff_size = 255; |
| 20 | char err_str[buff_size]; | 20 | char err_str[buff_size]; |
| 21 | 21 | ||
| 22 | #ifdef _WIN32 | 22 | #ifdef _WIN32 |
| 23 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), | 23 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), |
| 24 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); | 24 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr); |
| 25 | return std::string(err_str, buff_size); | ||
| 26 | #elif defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600)) | ||
| 27 | // Thread safe (GNU-specific) | ||
| 28 | const char* str = strerror_r(errno, err_str, buff_size); | ||
| 29 | return std::string(str); | ||
| 25 | #else | 30 | #else |
| 26 | // Thread safe (XSI-compliant) | 31 | // Thread safe (XSI-compliant) |
| 27 | strerror_r(errno, err_str, buff_size); | 32 | const int success = strerror_r(errno, err_str, buff_size); |
| 33 | if (success != 0) { | ||
| 34 | return {}; | ||
| 35 | } | ||
| 36 | return std::string(err_str); | ||
| 28 | #endif | 37 | #endif |
| 29 | |||
| 30 | return std::string(err_str, buff_size); | ||
| 31 | } | 38 | } |