Changeset 155883 in webkit


Ignore:
Timestamp:
Sep 16, 2013 10:50:20 AM (11 years ago)
Author:
andersca@apple.com
Message:

Change a couple of COMPILE_ASSERTs to static_assert
https://bugs.webkit.org/show_bug.cgi?id=121441

Reviewed by Andreas Kling.

  • wtf/BloomFilter.h:
  • wtf/PackedIntVector.h:

(WTF::PackedIntVector::PackedIntVector):

  • wtf/StdLibExtras.h:

(WTF::bitwise_cast):
(WTF::safeCast):
(WTF::roundUpToMultipleOf):

  • wtf/StringHasher.h:

(WTF::StringHasher::hashMemory):

  • wtf/Vector.h:
  • wtf/text/AtomicString.cpp:
  • wtf/unicode/Unicode.h:
Location:
trunk/Source/WTF
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r155832 r155883  
     12013-09-16  Anders Carlsson  <andersca@apple.com>
     2
     3        Change a couple of COMPILE_ASSERTs to static_assert
     4        https://bugs.webkit.org/show_bug.cgi?id=121441
     5
     6        Reviewed by Andreas Kling.
     7
     8        * wtf/BloomFilter.h:
     9        * wtf/PackedIntVector.h:
     10        (WTF::PackedIntVector::PackedIntVector):
     11        * wtf/StdLibExtras.h:
     12        (WTF::bitwise_cast):
     13        (WTF::safeCast):
     14        (WTF::roundUpToMultipleOf):
     15        * wtf/StringHasher.h:
     16        (WTF::StringHasher::hashMemory):
     17        * wtf/Vector.h:
     18        * wtf/text/AtomicString.cpp:
     19        * wtf/unicode/Unicode.h:
     20
    1212013-09-15  Gustavo Noronha Silva  <gns@gnome.org>
    222
  • trunk/Source/WTF/wtf/BloomFilter.h

    r149673 r155883  
    3838    WTF_MAKE_FAST_ALLOCATED;
    3939public:
    40     COMPILE_ASSERT(keyBits <= 16, bloom_filter_key_size);
     40    static_assert(keyBits <= 16, "BloomFilter key size must be less than or equal to 16!");
    4141
    4242    static const size_t tableSize = 1 << keyBits;
  • trunk/Source/WTF/wtf/PackedIntVector.h

    r151689 r155883  
    4141class PackedIntVector {
    4242public:
     43    static_assert(bitCount, "bitCount must not be zero!");
     44    static_assert(bitCount < sizeof(void*) * 8, "bitCount must not exceed the address space limit!");
     45
    4346    PackedIntVector()
    4447    {
    45         COMPILE_ASSERT(bitCount, bitCount_shall_not_be_zero);
    46         COMPILE_ASSERT(bitCount < sizeof(void*) * 8, bitCount_shall_not_exceed_address_space_limit);
    4748    }
    4849   
  • trunk/Source/WTF/wtf/StdLibExtras.h

    r155280 r155883  
    130130 * C++'s idea of a reinterpret_cast lacks sufficient cojones.
    131131 */
    132 template<typename TO, typename FROM>
    133 inline TO bitwise_cast(FROM from)
    134 {
    135     COMPILE_ASSERT(sizeof(TO) == sizeof(FROM), WTF_bitwise_cast_sizeof_casted_types_is_equal);
     132template<typename ToType, typename FromType>
     133inline ToType bitwise_cast(FromType from)
     134{
     135    static_assert(sizeof(FromType) == sizeof(ToType), "bitwise_cast size of FromType and ToType must be equal!");
    136136    union {
    137         FROM from;
    138         TO to;
     137        FromType from;
     138        ToType to;
    139139    } u;
    140140    u.from = from;
     
    142142}
    143143
    144 template<typename To, typename From>
    145 inline To safeCast(From value)
    146 {
    147     ASSERT(isInBounds<To>(value));
    148     return static_cast<To>(value);
     144template<typename ToType, typename FromType>
     145inline ToType safeCast(FromType value)
     146{
     147    ASSERT(isInBounds<ToType>(value));
     148    return static_cast<ToType>(value);
    149149}
    150150
     
    172172    return (x + remainderMask) & ~remainderMask;
    173173}
     174
    174175template<size_t divisor> inline size_t roundUpToMultipleOf(size_t x)
    175176{
    176     COMPILE_ASSERT(divisor && !(divisor & (divisor - 1)), divisor_is_a_power_of_two);
     177    static_assert(divisor && !(divisor & (divisor - 1)), "divisor must be a power of two!");
    177178    return roundUpToMultipleOf(divisor, x);
    178179}
  • trunk/Source/WTF/wtf/StringHasher.h

    r144552 r155883  
    249249    template<size_t length> static unsigned hashMemory(const void* data)
    250250    {
    251         COMPILE_ASSERT(!(length % 2), length_must_be_a_multiple_of_two);
     251        static_assert(!(length % 2), "length must be a multiple of two!");
    252252        return hashMemory(data, length);
    253253    }
  • trunk/Source/WTF/wtf/Vector.h

    r155748 r155883  
    175175    static void uninitializedFill(T* dst, T* dstEnd, const T& val)
    176176    {
    177         COMPILE_ASSERT(sizeof(T) == sizeof(char), Size_of_type_should_be_equal_to_one);
     177        static_assert(sizeof(T) == 1, "Size of type T should be equal to one!");
    178178#if COMPILER(GCC) && defined(_FORTIFY_SOURCE)
    179179        if (!__builtin_constant_p(dstEnd - dst) || (!(dstEnd - dst)))
  • trunk/Source/WTF/wtf/text/AtomicString.cpp

    r152816 r155883  
    4141using namespace Unicode;
    4242
    43 COMPILE_ASSERT(sizeof(AtomicString) == sizeof(String), atomic_string_and_string_must_be_same_size);
     43static_assert(sizeof(AtomicString) == sizeof(String), "AtomicString and String must be same size!");
    4444
    4545#if USE(WEB_THREAD)
  • trunk/Source/WTF/wtf/unicode/Unicode.h

    r142761 r155883  
    3737#endif
    3838
    39 COMPILE_ASSERT(sizeof(UChar) == 2, UCharIsTwoBytes);
     39static_assert(sizeof(UChar) == 2, "UChar must be two bytes!");
    4040
    4141#endif // WTF_UNICODE_H
Note: See TracChangeset for help on using the changeset viewer.