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

Unified Diff: third_party/WebKit/Source/platform/LayoutUnit.h

Issue 2261663002: Disallow cast/implicit conversion from LayoutUnit to int/unsigned (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: - Created 4 years, 4 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
Index: third_party/WebKit/Source/platform/LayoutUnit.h
diff --git a/third_party/WebKit/Source/platform/LayoutUnit.h b/third_party/WebKit/Source/platform/LayoutUnit.h
index 700aef96bd08df3423fe5895456321b7f03893b8..cff94492f6c2c4f9f7ab2b1c8fb6633a41faa4f1 100644
--- a/third_party/WebKit/Source/platform/LayoutUnit.h
+++ b/third_party/WebKit/Source/platform/LayoutUnit.h
@@ -107,8 +107,12 @@ public:
}
unsigned toUnsigned() const { REPORT_OVERFLOW(m_value >= 0); return toInt(); }
- operator int() const { return toInt(); }
- operator unsigned() const { return toUnsigned(); }
+ // Conversion to int or unsigned is lossy. 'explicit' on these operators won't work because
+ // there are also other implicit conversion paths (e.g. operator bool then to int which would
+ // generate wrong result). Use toInt() and toUnsigned() instead.
+ operator int() const = delete;
+ operator unsigned() const = delete;
+
operator double() const { return toDouble(); }
operator float() const { return toFloat(); }
operator bool() const { return m_value; }
« no previous file with comments | « third_party/WebKit/Source/core/testing/Internals.cpp ('k') | third_party/WebKit/Source/platform/LengthFunctions.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698