libchromeos: get rid of unused-local-typedef warning.
This uses static_assert() to issue a meaningful compile-time error.
To prevent this from happening for all references to RawCast, use sizeof(T)
to make static_assert depend on type T and therefore prevent binding it
unconditionally until the actual RawCast<T> instantiation happens.
BUG=chromium:450380
TEST=builds with new clang.
Change-Id: I6aaf3e5e69b239288400accfee50e5adfd54c200
Reviewed-on: https://chromium-review.googlesource.com/242047
Reviewed-by: Alex Vakulenko <[email protected]>
Tested-by: Yunlian Jiang <[email protected]>
Commit-Queue: Yunlian Jiang <[email protected]>
diff --git a/chromeos/glib/object.h b/chromeos/glib/object.h
index eb8f9cb..9bbdb33 100644
--- a/chromeos/glib/object.h
+++ b/chromeos/glib/object.h
@@ -144,7 +144,11 @@
template <typename T>
inline T RawCast(const ::GValue& x) {
- typedef typename T::function_not_defined type;
+ // Use static_assert() to issue a meaningful compile-time error.
+ // To prevent this from happening for all references to RawCast, use sizeof(T)
+ // to make static_assert depend on type T and therefore prevent binding it
+ // unconditionally until the actual RawCast<T> instantiation happens.
+ static_assert(sizeof(T) == 0, "Using RawCast on unsupported type");
return T();
}