From ff03f932bfa8cc3602ac3b8fe5096240726246e8 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 27 Apr 2021 03:16:56 +0100 Subject: [PATCH] Add messages to `static_assert` Single-argument version is allegedly not supported by GCC < 9.1, though it seemed to work fine. https://www.gnu.org/software/gnulib/manual/html_node/assert_002eh.html --- Source/mpqapi.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/mpqapi.cpp b/Source/mpqapi.cpp index 0cea0073d..d438d41c6 100644 --- a/Source/mpqapi.cpp +++ b/Source/mpqapi.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -35,11 +36,11 @@ namespace { // Done with templates so that error messages include actual size. template struct assert_eq : std::true_type { - static_assert(A == B); + static_assert(A == B, "A == B not satisfied"); }; template struct assert_lte : std::true_type { - static_assert(A <= B); + static_assert(A <= B, "A <= B not satisfied"); }; template struct check_size : assert_eq, assert_lte { @@ -48,8 +49,8 @@ struct check_size : assert_eq, assert_lte { // Check sizes and alignments of the structs that we decrypt and encrypt. // The decryption algorithm treats them as a stream of 32-bit uints, so the // sizes must be exact as there cannot be any padding. -static_assert(check_size<_HASHENTRY, 4 * 4>::value); -static_assert(check_size<_BLOCKENTRY, 4 * 4>::value); +static_assert(check_size<_HASHENTRY, 4 * 4>::value, "sizeof(_HASHENTRY) == 4 * 4 && alignof(_HASHENTRY) <= 4 * 4 not satisfied"); +static_assert(check_size<_BLOCKENTRY, 4 * 4>::value, "sizeof(_BLOCKENTRY) == 4 * 4 && alignof(_BLOCKENTRY) <= 4 * 4 not satisfied"); const char *DirToString(std::ios::seekdir dir) {