]> www.ginac.de Git - cln.git/commitdiff
Replace typedef int[<negative>] trick with static_assert.
authorRichard Kreckel <kreckel@ginac.de>
Sun, 27 Oct 2019 13:57:36 +0000 (14:57 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 27 Oct 2019 13:57:36 +0000 (14:57 +0100)
include/cln/number.h
m4/floatparam.m4
m4/intparam.m4

index aeb7d2d20989b22bfd0b7ec01190dc7597625d9a..8abb22bfd6b600e883373c2abf233b6790c32ce3 100644 (file)
@@ -257,7 +257,8 @@ template<class type>
 inline const type& the(const cl_number& x)
 {
        // check that sizeof(type)==sizeof(cl_number)
-       int (*dummy1)(int assertion1 [1 - 2 * (sizeof(type) != sizeof(cl_number))]); (void)dummy1;
+       static_assert(sizeof(type)==sizeof(cl_number),
+                     "sizeof(type)!=sizeof(cl_number)");
        return *(const type *) &x;
 }
 // Conversions to subtypes without checking, macro version:
index 56dd53e860b668691a0acfe2f366a5dbe2872a84..6afda75b2af015474ef0492de073eaf4f14079d3 100644 (file)
@@ -22,20 +22,16 @@ AC_DEFUN([CL_FLOATPARAM_CROSS],
         epsilon_bits=-1; y="($type)1.0"
         while true; do
           AC_TRY_COMPILE([],
-            [typedef int verify[2*(
-               (($type)(($type)1.0 + ($type)($y)) == ($type)1.0)
-               || ($type)(($type)(($type)1.0 + ($type)($y)) - ($type)1.0) != ($type)($y)
-             ) - 1];],
+            [static_assert((($type)(($type)1.0 + ($type)($y)) == ($type)1.0)
+                         || ($type)(($type)(($type)1.0 + ($type)($y)) - ($type)1.0) != ($type)($y), "");],
             [break;])
           epsilon_bits=`expr $epsilon_bits + 1`; y="$y * ($type)0.5"
         done
         negepsilon_bits=-1; y="($type)-1.0"
         while true; do
           AC_TRY_COMPILE([],
-            [typedef int verify[2*(
-               (($type)(($type)1.0 + ($type)($y)) == ($type)1.0)
-               || ($type)(($type)(($type)1.0 + ($type)($y)) - ($type)1.0) != ($type)($y)
-             ) - 1];],
+            [static_assert((($type)(($type)1.0 + ($type)($y)) == ($type)1.0)
+                         || ($type)(($type)(($type)1.0 + ($type)($y)) - ($type)1.0) != ($type)($y), "");],
             [break;])
           negepsilon_bits=`expr $negepsilon_bits + 1`; y="$y * ($type)0.5"
         done
@@ -68,30 +64,22 @@ AC_DEFUN([CL_FLOATPARAM_CROSS],
         rounds=
         if test -z "$rounds"; then
           AC_TRY_COMPILE([],
-            [typedef int verify[2*(
-               $ys1 == $y1 && $ys2 == $y2 && $zs1 == $z1 && $zs2 == $z2
-             ) - 1];],
+            [static_assert($ys1 == $y1 && $ys2 == $y2 && $zs1 == $z1 && $zs2 == $z2, "");],
             [rounds=rounds_to_nearest])
         fi
         if test -z "$rounds"; then
           AC_TRY_COMPILE([],
-            [typedef int verify[2*(
-               $ys1 == $y1 && $ys2 == $y1 && $zs1 == $z1 && $zs2 == $z1
-             ) - 1];],
+            [static_assert($ys1 == $y1 && $ys2 == $y1 && $zs1 == $z1 && $zs2 == $z1, "");],
             [rounds=rounds_to_zero])
         fi
         if test -z "$rounds"; then
           AC_TRY_COMPILE([],
-            [typedef int verify[2*(
-               $ys1 == $y2 && $ys2 == $y2 && $zs1 == $z1 && $zs2 == $z1
-             ) - 1];],
+            [static_assert($ys1 == $y2 && $ys2 == $y2 && $zs1 == $z1 && $zs2 == $z1, "");],
             [rounds=rounds_to_infinity])
         fi
         if test -z "$rounds"; then
           AC_TRY_COMPILE([],
-            [typedef int verify[2*(
-               $ys1 == $y1 && $ys2 == $y1 && $zs1 == $z2 && $zs2 == $z2
-             ) - 1];],
+            [static_assert($ys1 == $y1 && $ys2 == $y1 && $zs1 == $z2 && $zs2 == $z2, "");],
             [rounds=rounds_to_minus_infinity])
         fi
         if test -n "$rounds"; then
index b9967bbaeebee063aa3a9d4bc9a8d6443ad7519a..d8536b2c7d817504abb8cc63f5fe8cd10acb4be7 100644 (file)
@@ -113,7 +113,7 @@ AC_DEFUN([CL_INTPARAM_CROSS],
         echo "#error \"Integer types long long and unsigned long long have different sizes!!\""
       fi
     fi
-    AC_TRY_COMPILE([], [typedef int verify[2*(sizeof(char*)<=sizeof (long))-1];],
+    AC_TRY_COMPILE([], [static_assert(sizeof(char*) <= sizeof(long), "");],
       [], [echo "#error \"Type char * does not fit into a long!!\""])
     _AC_COMPUTE_INT([sizeof (char *)], [pointer_size])
     pointer_bitsize=`expr $pointer_size '*' $char_bitsize`
@@ -258,7 +258,7 @@ AC_DEFUN([CL_INTPARAM_BITSIZE],
 [
   n=1; x="($1)2"
   while true; do
-    AC_TRY_COMPILE([], [typedef int verify[2*(($1)($x) == 0) - 1];],
+    AC_TRY_COMPILE([], [static_assert(($1)($x) == 0, "");],
       [$2=$n; break;],
       [if test $n = 1000; then $2=; break; fi;])
     n=`expr $n + 1`; x="$x * ($1)2"
@@ -290,7 +290,7 @@ AC_DEFUN([CL_INTPARAM_ALIGNOF],
 #else
 # define alignof(type)  offsetof (struct { char slot1; type slot2; }, slot2)
 #endif
-], [typedef int verify[2*(alignof($1) == $n) - 1];],
+], [static_assert(alignof($1) == $n, "");],
       [$2=$n; break;]
       [if test $n = 0; then $2=; break; fi])
     n=`expr $n '*' 2`