Make SkASSERT and co. constexpr compatible.

One of the nice bits of constexpr is that an expression is constexpr if
there exists any set of argument values that make it constant.  It
doesn't have to be constant for _all_ argument values.

This means that this expression is constexpr:

   condition ? constexpr_value
             : []{ arbitrary non-constexpr code; }();

... it's constant when condition is true.

We can use this to rewrite SkASSERT(condition) as

    ( (condition) ? (void)0
                  : []{ SK_ABORT(#condition); }() )

Both sides of the ?: are void, and when condition is true at compile
time the right hand side disappears completely.  In C++11 constexpr
functions we just have to use the comma operator to jam SkASSERT()
into the order of evaluation:

    constexpr uint32_t foo(int x, int y) {
        return SkASSERT(x > y),
               x - y;
    }

Change-Id: I21878d14fb2af76d93591d2ae229460ee825cfde
Reviewed-on: https://skia-review.googlesource.com/52663
Reviewed-by: Ben Wagner <bungeman@google.com>
Reviewed-by: Trent Apted <tapted@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index b453249..63a2b40 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -79,27 +79,33 @@
     SK_API void SkDebugf(const char format[], ...);
 #endif
 
-#define SkREQUIRE_SEMICOLON_AFTER(code) do { code } while (false)
-
+// SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g.
+//    uint32_t foo(int x) {
+//        SkASSERT(x > 4);
+//        return x - 4;
+//    }
+// and are also written to be compatible with constexpr functions:
+//    constexpr uint32_t foo(int x) {
+//        return SkASSERT(x > 4),
+//               x - 4;
+//    }
 #define SkASSERT_RELEASE(cond) \
-    SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT(#cond); } )
+        static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(" #cond ")"); }() )
 
 #ifdef SK_DEBUG
-    #define SkASSERT(cond) \
-        SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT("assert(" #cond ")"); })
-    #define SkASSERTF(cond, fmt, ...) \
-        SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { \
-                                      SkDebugf(fmt"\n", __VA_ARGS__); \
-                                      SK_ABORT("assert(" #cond ")"); \
-                                  })
+    #define SkASSERT(cond) SkASSERT_RELEASE(cond)
+    #define SkASSERTF(cond, fmt, ...) static_cast<void>( (cond) ? (void)0 : [&]{ \
+                                          SkDebugf(fmt"\n", __VA_ARGS__);        \
+                                          SK_ABORT("assert(" #cond ")");         \
+                                      }() )
     #define SkDEBUGFAIL(message)        SK_ABORT(message)
     #define SkDEBUGFAILF(fmt, ...)      SkASSERTF(false, fmt, ##__VA_ARGS__)
     #define SkDEBUGCODE(...)            __VA_ARGS__
     #define SkDEBUGF(args       )       SkDebugf args
     #define SkAssertResult(cond)        SkASSERT(cond)
 #else
-    #define SkASSERT(cond)
-    #define SkASSERTF(cond, fmt, ...)
+    #define SkASSERT(cond)            static_cast<void>(0)
+    #define SkASSERTF(cond, fmt, ...) static_cast<void>(0)
     #define SkDEBUGFAIL(message)
     #define SkDEBUGFAILF(fmt, ...)
     #define SkDEBUGCODE(...)