Safeguard base::ArraySize from misuse
Possible misuse with previous impl: Passing array pointer.
Safeguard: Compilation failure if array pointer passed.
Change-Id: I6989bb360d28b3ac624b587e8e5f4f6045be8f9f
diff --git a/include/perfetto/ext/base/utils.h b/include/perfetto/ext/base/utils.h
index 4c4b66b..99a9802 100644
--- a/include/perfetto/ext/base/utils.h
+++ b/include/perfetto/ext/base/utils.h
@@ -62,9 +62,9 @@
// similar mm-related syscalls.
uint32_t GetSysPageSize();
-template <typename T>
-constexpr size_t ArraySize(const T& array) {
- return sizeof(array) / sizeof(array[0]);
+template <typename T, size_t TSize>
+constexpr size_t ArraySize(const T (&)[TSize]) {
+ return TSize;
}
// Function object which invokes 'free' on its parameter, which must be