Skip to content

Commit bb0b32c

Browse files
committed
Fix build error risks with sparsehash
1 parent 116b86c commit bb0b32c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

vendor/sparsehash/src/sparsehash/internal/hashtable-common.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,20 @@
5050
_START_GOOGLE_NAMESPACE_
5151

5252
template <bool> struct SparsehashCompileAssert { };
53-
#define SPARSEHASH_COMPILE_ASSERT(expr, msg) \
54-
[[maybe_unused]] typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
53+
54+
// Cross-platform compatibility for unused attribute
55+
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
56+
#define SPARSEHASH_COMPILE_ASSERT(expr, msg) \
57+
[[maybe_unused]] typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
58+
#elif defined(__GNUC__) || defined(__clang__)
59+
// GCC or Clang: use GNU attribute
60+
#define SPARSEHASH_COMPILE_ASSERT(expr, msg) \
61+
__attribute__((unused)) typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
62+
#else
63+
// Other compilers: No attribute
64+
#define SPARSEHASH_COMPILE_ASSERT(expr, msg) \
65+
typedef SparsehashCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
66+
#endif
5567

5668
namespace sparsehash_internal {
5769

0 commit comments

Comments
 (0)