Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1199)

Unified Diff: base/metrics/histogram_macros.h

Issue 2469993002: Assert enum type equivalence in UMA_HISTOGRAM_ENUMERATION (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_macros.h
diff --git a/base/metrics/histogram_macros.h b/base/metrics/histogram_macros.h
index 63cca694e9ad2d3d5ab36b99b6b426f14e628692..ded241b9906686992c72029b659d2e7d50b855af 100644
--- a/base/metrics/histogram_macros.h
+++ b/base/metrics/histogram_macros.h
@@ -41,10 +41,15 @@
// delete and reused. The value in |sample| must be strictly less than
// |enum_max|.
-#define UMA_HISTOGRAM_ENUMERATION(name, sample, enum_max) \
- INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG( \
- name, sample, enum_max, \
- base::HistogramBase::kUmaTargetedHistogramFlag)
+#define UMA_HISTOGRAM_ENUMERATION(name, sample, enum_max) \
+ static_assert( \
Alexei Svitkine (slow) 2016/11/02 15:48:47 Thanks for working on this! Just a nit, can you m
wychen 2016/11/02 21:45:04 Done.
+ !std::is_enum<decltype(sample)>::value || \
+ !std::is_enum<decltype(enum_max)>::value || \
+ std::is_same<std::remove_const<decltype(sample)>::type, \
+ std::remove_const<decltype(enum_max)>::type>::value, \
+ "UMA_HISTOGRAM_ENUMERATION type incompatible"); \
+ INTERNAL_HISTOGRAM_ENUMERATION_WITH_FLAG( \
+ name, sample, enum_max, base::HistogramBase::kUmaTargetedHistogramFlag)
// Histogram for boolean values.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698