Title: [174193] trunk/Source/WTF
Revision
174193
Author
cdu...@apple.com
Date
2014-10-01 18:18:46 -0700 (Wed, 01 Oct 2014)

Log Message

Fail better when is<>() / downcast<>() is used for an unsupported type
https://bugs.webkit.org/show_bug.cgi?id=137323

Reviewed by Benjamin Poulain.

We should fail better when is<>() / downcast<>() is used for an
unsupported type (i.e. a type that doesn't have the needed
TypeCastTraits template specialization). Previously, we would get an
obscure linking error, which was sub-optimal.

With this patch, you would now hit a static_assert() at build time if
you tried to use is<>() / downcast<>() for a type that did not have the
needed template specialization. There is also a helpful comment above
the assertion letting the developer know how to add the needed template
specialization.

* wtf/TypeCasts.h:
(WTF::TypeCastTraits::isOfType):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (174192 => 174193)


--- trunk/Source/WTF/ChangeLog	2014-10-02 00:58:35 UTC (rev 174192)
+++ trunk/Source/WTF/ChangeLog	2014-10-02 01:18:46 UTC (rev 174193)
@@ -1,3 +1,24 @@
+2014-10-01  Christophe Dumez  <cdu...@apple.com>
+
+        Fail better when is<>() / downcast<>() is used for an unsupported type
+        https://bugs.webkit.org/show_bug.cgi?id=137323
+
+        Reviewed by Benjamin Poulain.
+
+        We should fail better when is<>() / downcast<>() is used for an
+        unsupported type (i.e. a type that doesn't have the needed
+        TypeCastTraits template specialization). Previously, we would get an
+        obscure linking error, which was sub-optimal.
+
+        With this patch, you would now hit a static_assert() at build time if
+        you tried to use is<>() / downcast<>() for a type that did not have the
+        needed template specialization. There is also a helpful comment above
+        the assertion letting the developer know how to add the needed template
+        specialization.
+
+        * wtf/TypeCasts.h:
+        (WTF::TypeCastTraits::isOfType):
+
 2014-10-01  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, rolling out r174180, r174183, and r174186.

Modified: trunk/Source/WTF/wtf/TypeCasts.h (174192 => 174193)


--- trunk/Source/WTF/wtf/TypeCasts.h	2014-10-02 00:58:35 UTC (rev 174192)
+++ trunk/Source/WTF/wtf/TypeCasts.h	2014-10-02 01:18:46 UTC (rev 174193)
@@ -26,11 +26,21 @@
 #ifndef TypeCasts_h
 #define TypeCasts_h
 
+#include <type_traits>
+
 namespace WTF {
 
 template <typename ExpectedType, typename ArgType>
 struct TypeCastTraits {
-    static bool isOfType(ArgType&);
+    static bool isOfType(ArgType&)
+    {
+        // If you're hitting this assertion, it is likely because you used
+        // is<>() or downcast<>() with a type that doesn't have the needed
+        // TypeCastTraits specialization. Please use the following macro
+        // to add that specialization:
+        // SPECIALIZE_TYPE_TRAITS_BEGIN() / SPECIALIZE_TYPE_TRAITS_END()
+        static_assert(std::is_void<ExpectedType>::value, "Missing TypeCastTraits specialization");
+    }
 };
 
 template <typename ExpectedType>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to