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

Unified Diff: base/mac/foundation_util.h

Issue 1927003004: Mac: Introduce "StaticCast" variants of base::mac::FooCastStrict, which do not typecheck in Release (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months 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 | base/mac/foundation_util.mm » ('j') | base/mac/foundation_util.mm » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/foundation_util.h
diff --git a/base/mac/foundation_util.h b/base/mac/foundation_util.h
index ee23a17fb16e6c0c5c6856c6cd0ccbd9dd43c120..6505e614ed56b2120a23d8318126a90bc063112f 100644
--- a/base/mac/foundation_util.h
+++ b/base/mac/foundation_util.h
@@ -272,14 +272,16 @@ template<typename T>
T CFCast(const CFTypeRef& cf_val);
template<typename T>
-T CFCastStrict(const CFTypeRef& cf_val);
+T CFCastStrict(const CFTypeRef& cf_val) {
+ DCHECK(!cf_val || CFCast<T>(cf_val));
+ // Note: CFTypeRef is const void*, but CGColorRef and some others are non-
+ // const. So this may also cast away a const qualifier.
+ return (T)(cf_val);
+}
#define CF_CAST_DECL(TypeCF) \
template<> BASE_EXPORT TypeCF##Ref \
-CFCast<TypeCF##Ref>(const CFTypeRef& cf_val);\
-\
-template<> BASE_EXPORT TypeCF##Ref \
-CFCastStrict<TypeCF##Ref>(const CFTypeRef& cf_val);
+CFCast<TypeCF##Ref>(const CFTypeRef& cf_val);
CF_CAST_DECL(CFArray);
CF_CAST_DECL(CFBag);
@@ -339,9 +341,8 @@ T* ObjCCast(id objc_val) {
template<typename T>
T* ObjCCastStrict(id objc_val) {
- T* rv = ObjCCast<T>(objc_val);
- DCHECK(objc_val == nil || rv);
- return rv;
+ DCHECK(!objc_val || ObjCCast<T>(objc_val));
+ return reinterpret_cast<T*>(objc_val);
}
#endif // defined(__OBJC__)
« no previous file with comments | « no previous file | base/mac/foundation_util.mm » ('j') | base/mac/foundation_util.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698