aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAyrton Munoz <ayrton@google.com>2022-10-15 00:53:07 -0400
committerAyrton Munoz <ayrton@google.com>2022-10-17 22:17:38 -0400
commit4ddd4c1b4914daba9e9b7ae32d448cf706110d09 (patch)
treef4e746b7f591aa64b3254a84f33a7fa70d0e88b2 /lib
parent6112644219b18170dbe9d0ca2ef4c38ef549b0d6 (diff)
downloadcommon-4ddd4c1b4914daba9e9b7ae32d448cf706110d09.tar.gz
include/compiler.h: Replace countof macro with inline function in C++
libcxx's locale.cpp defines an internal countof function so this commit replaces that macro with an inline function definition whenever compiler.h is included in C++. It also adds the countof macro in two host tests that call countof on pointers to empty arrays since zero-sized arrays are not permitted in C++. Bug: 230134581 Change-Id: I4d8dc311f86a1e6df5231ca4a16587023becca58
Diffstat (limited to 'lib')
-rw-r--r--lib/binary_search_tree/hosttest/binary_search_tree_test.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/binary_search_tree/hosttest/binary_search_tree_test.cpp b/lib/binary_search_tree/hosttest/binary_search_tree_test.cpp
index 4e68a2e7..00dee5b1 100644
--- a/lib/binary_search_tree/hosttest/binary_search_tree_test.cpp
+++ b/lib/binary_search_tree/hosttest/binary_search_tree_test.cpp
@@ -297,10 +297,12 @@ static void bst_test_check_array(struct bst_root *root,
EXPECT_EQ(bst_next(root, bst_node(nodes, index, count - 1, count)), right);
EXPECT_EQ(bst_prev(root, right), bst_node(nodes, index, count - 1, count));}
+#define bst_countof(a) (sizeof(a) / sizeof((a))[0])
+
#define bst_test_check(root, nodes, items...) do { \
SCOPED_TRACE("bst_test_check"); \
size_t index[] = {items}; \
- bst_test_check_array(root, nodes, index, countof(index), NULL, NULL); \
+ bst_test_check_array(root, nodes, index, bst_countof(index), NULL, NULL); \
if (HasFatalFailure()) return; \
} while(0)