Replace DALI_COMPILE_TIME_ASSERT with C++11 static_assert 55/136455/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 29 Jun 2017 17:43:49 +0000 (18:43 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 29 Jun 2017 17:56:31 +0000 (18:56 +0100)
Change-Id: Ieaf5b9b3f75d7d7a2fc5d29edda5e5c62ed672f6

automated-tests/src/dali/utc-Dali-ConditionalWait.cpp
automated-tests/src/dali/utc-Dali-Mutex.cpp
automated-tests/src/dali/utc-Dali-Thread.cpp
dali/internal/render/gl-resources/context.cpp
dali/internal/update/manager/transform-manager.cpp
dali/public-api/math/compile-time-math.cpp
dali/public-api/signals/functor-delegate.cpp

index 88a3902..3ab2f36 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #include <iostream>
 #include <stdlib.h>
 #include <unistd.h>
+#include <type_traits>
 #include <dali-test-suite-utils.h>
 #include <dali/devel-api/threading/conditional-wait.h>
 #include <dali/devel-api/threading/thread.h>
@@ -250,7 +251,7 @@ int UtcConditionalWaitNonCopyable(void)
 {
   // we want to make sure that ConditionalWait is not copyable (its copy constructor is not defined)
   // this test will stop compiling if ConditionalWait has compiler generated copy constructor
-  DALI_COMPILE_TIME_ASSERT( !__has_trivial_copy( ConditionalWait ) );
+  static_assert( !__has_trivial_copy( ConditionalWait ), "ConditionalWait should NOT be copyable" );
 
   DALI_TEST_CHECK( true );
   END_TEST;
index 8a1a5b0..44ca204 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #include <iostream>
 #include <stdlib.h>
 #include <unistd.h>
+#include <type_traits>
 #include <dali/public-api/dali-core.h>
 #include <dali/devel-api/threading/mutex.h>
 #include <dali/devel-api/threading/thread.h>
@@ -133,7 +134,7 @@ int UtcDaliMutexNonCopyable(void)
 {
   // we want to make sure that mutex is not copyable (its copy constructor is not defined)
   // this test will stop compiling if Mutex has compiler generated copy constructor
-  DALI_COMPILE_TIME_ASSERT( !__has_trivial_copy( Mutex ) );
+  static_assert( !__has_trivial_copy( Mutex ), "Mutex should NOT be copyable" );
 
   DALI_TEST_CHECK( true );
   END_TEST;
index a62fde7..fafc10b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #include <iostream>
 #include <stdlib.h>
 #include <unistd.h>
+#include <type_traits>
 #include <dali-test-suite-utils.h>
 #include <dali/devel-api/threading/thread.h>
 
@@ -72,7 +73,7 @@ int UtcDaliThreadNonCopyable(void)
 {
   // we want to make sure that mutex is not copyable (its copy constructor is not defined)
   // this test will stop compiling if Mutex has compiler generated copy constructor
-  DALI_COMPILE_TIME_ASSERT( !__has_trivial_copy( Thread ) );
+  static_assert( !__has_trivial_copy( Thread ), "Thread should NOT be copyable" );
 
   DALI_TEST_CHECK( true );
   END_TEST;
index 041565e..2d883bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,9 +21,9 @@
 // EXTERNAL INCLUDES
 #include <algorithm>
 #include <cstring>
+#include <type_traits>
 
 // INTERNAL INCLUDES
-#include <dali/public-api/common/compile-time-assert.h>
 #include <dali/public-api/common/constants.h>
 #include <dali/public-api/rendering/texture-set.h>
 #include <dali/integration-api/platform-abstraction.h>
@@ -39,7 +39,7 @@ namespace Internal
 namespace // unnamed namespace
 {
 
-DALI_COMPILE_TIME_ASSERT( TEXTURE_UNIT_LAST <= Context::MAX_TEXTURE_UNITS );
+static_assert( TEXTURE_UNIT_LAST <= Context::MAX_TEXTURE_UNITS, "TEXTURE_UNIT_LAST is greater than Context::MAX_TEXTURE_UNITS" );
 
 /**
  * GL error strings
index 0d55efe..e72ea69 100644 (file)
 //EXTERNAL INCLUDES
 #include <algorithm>
 #include <cstring>
+#include <type_traits>
 
 //INTERNAL INCLUDES
 #include <dali/public-api/common/constants.h>
-#include <dali/public-api/common/compile-time-assert.h>
 #include <dali/internal/common/math.h>
 
 namespace Dali
@@ -44,8 +44,8 @@ static const float gDefaultTransformComponentAnimatableData[] = { 1.0f, 1.0f, 1.
 //Default values for anchor point (CENTER) and parent origin (TOP_LEFT)
 static const float gDefaultTransformComponentStaticData[] = { 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 0.5f, true };
 
-DALI_COMPILE_TIME_ASSERT( sizeof(gDefaultTransformComponentAnimatableData) == sizeof(TransformComponentAnimatable) );
-DALI_COMPILE_TIME_ASSERT( sizeof(gDefaultTransformComponentStaticData) == sizeof(TransformComponentStatic) );
+static_assert( sizeof(gDefaultTransformComponentAnimatableData) == sizeof(TransformComponentAnimatable), "gDefaultTransformComponentAnimatableData should have the same number of floats as specified in TransformComponentAnimatable" );
+static_assert( sizeof(gDefaultTransformComponentStaticData) == sizeof(TransformComponentStatic), "gDefaultTransformComponentStaticData should have the same number of floats as specified in TransformComponentStatic" );
 
 /**
  * @brief Calculates the center position for the transform component
index 5199323..5948d78 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 // CLASS HEADER
 #include <dali/public-api/math/compile-time-math.h>
 
-// INTERNAL INCLUDES
-#include <dali/public-api/common/compile-time-assert.h>
+// EXTERNAL INCLUDES
+#include <type_traits>
 
 namespace Dali
 {
 
-namespace
-{
-  // verification for static asserts, these get removed from final binary by the linker
-  const unsigned int value0 = Power<10,0>::value;
-  DALI_COMPILE_TIME_ASSERT( value0 == 1 ); // cannot have template with , inside macro... macros suck
-  const unsigned int value1 = Power<10,1>::value;
-  DALI_COMPILE_TIME_ASSERT( value1 == 10 );
-  const unsigned int value2 = Power<10,2>::value;
-  DALI_COMPILE_TIME_ASSERT( value2 == 100 );
-  const unsigned int value3 = Power<10,3>::value;
-  DALI_COMPILE_TIME_ASSERT( value3 == 1000 );
-  const unsigned int value4 = Power<4,4>::value;
-  DALI_COMPILE_TIME_ASSERT( value4 == 256 );
-
-  const unsigned int log0 = Log<0, 10>::value;
-  DALI_COMPILE_TIME_ASSERT( log0 == 0 );
-  const unsigned int log1 = Log<1, 10>::value;
-  DALI_COMPILE_TIME_ASSERT( log1 == 0 );
-  const unsigned int log2 = Log<2, 10>::value;
-  DALI_COMPILE_TIME_ASSERT( log2 == 1 );
-  const unsigned int log3 = Log<10, 10>::value;
-  DALI_COMPILE_TIME_ASSERT( log3 == 1 );
-  const unsigned int log4 = Log<100, 10>::value;
-  DALI_COMPILE_TIME_ASSERT( log4 == 2 );
-  const unsigned int log5 = Log<1000, 10>::value;
-  DALI_COMPILE_TIME_ASSERT( log5 == 3 );
-
-  const unsigned int logpow0 = Log<Power<10,0>::value, 10 >::value;
-  DALI_COMPILE_TIME_ASSERT( logpow0 == 0 );
-  const unsigned int logpow1 = Log<Power<2,0>::value, 2 >::value;
-  DALI_COMPILE_TIME_ASSERT( logpow1 == 0 );
-  const unsigned int logpow2 = Log<Power<10,2>::value, 10 >::value;
-  DALI_COMPILE_TIME_ASSERT( logpow2 == 2 );
-  const unsigned int logpow3 = Log<Power<2,2>::value, 2 >::value;
-  DALI_COMPILE_TIME_ASSERT( logpow3 == 2 );
-
-  const unsigned int powlog0 = Power<10, Log<10,10>::value >::value;
-  DALI_COMPILE_TIME_ASSERT( powlog0 == 10 );
-  const unsigned int powlog1 = Power<10, Log<100,10>::value >::value;
-  DALI_COMPILE_TIME_ASSERT( powlog1 == 100 );
-
-  // TODO unfortunately cannot static assert floats so cannot test EPSILON here...
-
-} // namespace
+// verification for static asserts, these get removed from final binary by the linker
+static_assert( Power<10,0>::value == 1, "" );
+static_assert( Power<10,1>::value == 10, "" );
+static_assert( Power<10,2>::value == 100, "" );
+static_assert( Power<10,3>::value == 1000, "" );
+static_assert( Power<4,4>::value == 256, "" );
+
+static_assert( Log<0, 10>::value == 0, "" );
+static_assert( Log<1, 10>::value == 0, "" );
+static_assert( Log<2, 10>::value == 1, "" );
+static_assert( Log<10, 10>::value == 1, "" );
+static_assert( Log<100, 10>::value == 2, "" );
+static_assert( Log<1000, 10>::value == 3, "" );
+
+static_assert( Log<Power<10,0>::value, 10 >::value == 0, "" );
+static_assert( Log<Power<2,0>::value, 2 >::value == 0, "" );
+static_assert( Log<Power<10,2>::value, 10 >::value == 2, "" );
+static_assert( Log<Power<2,2>::value, 2 >::value == 2, "" );
+
+static_assert( Power<10, Log<10,10>::value >::value == 10, "" );
+static_assert( Power<10, Log<100,10>::value >::value == 100, "" );
+
+// TODO unfortunately cannot static assert floats so cannot test EPSILON here...
 
 } // namespace Dali
index 7f43284..8fafecd 100644 (file)
@@ -18,8 +18,8 @@
 // CLASS HEADER
 #include <dali/public-api/signals/functor-delegate.h>
 
-// INTERNAL INCLUDES
-#include <dali/public-api/common/compile-time-assert.h>
+// EXTERNAL INCLUDES
+#include <type_traits>
 
 namespace Dali
 {
@@ -31,7 +31,7 @@ namespace
  * functions and regular functions.
  * If this assert fails, please implement the template specialisation for C functions.
  */
-DALI_COMPILE_TIME_ASSERT( sizeof(void*) == sizeof( &FunctorDispatcher<void>::Dispatch ) );
+static_assert( sizeof(void*) == sizeof( &FunctorDispatcher<void>::Dispatch ), "Need to implement template specialisation for C functions" );
 }
 
 FunctorDelegate::~FunctorDelegate()