test-tgmath-ret.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Test compilation of tgmath macros.
  2. Copyright (C) 2003-2016 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Andreas Jaeger <aj@suse.de>, 2003.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <math.h>
  17. #include <complex.h>
  18. #include <tgmath.h>
  19. #include <stdio.h>
  20. static float fx;
  21. static double dx;
  22. static long double lx;
  23. static int errors = 0;
  24. static void
  25. our_error (const char *c)
  26. {
  27. puts (c);
  28. ++errors;
  29. }
  30. /* First function where the return type is constant. */
  31. #define CHECK_RET_CONST_TYPE(func, rettype, arg, name) \
  32. if (sizeof (func (arg)) != sizeof (rettype)) \
  33. our_error ("Return size of " #func " is wrong with " #name " argument");
  34. #define CHECK_RET_CONST_FLOAT(func, rettype) \
  35. CHECK_RET_CONST_TYPE (func, rettype, fx, float)
  36. #define CHECK_RET_CONST_DOUBLE(func, rettype) \
  37. CHECK_RET_CONST_TYPE (func, rettype, dx, double)
  38. #ifdef NO_LONG_DOUBLE
  39. # define CHECK_RET_CONST_LDOUBLE(func, rettype)
  40. #else
  41. # define CHECK_RET_CONST_LDOUBLE(func, rettype) \
  42. CHECK_RET_CONST_TYPE (func, rettype, lx, long double)
  43. #endif
  44. #define CHECK_RET_CONST(func, rettype) \
  45. static void \
  46. check_return_ ##func (void) \
  47. { \
  48. CHECK_RET_CONST_FLOAT (func, rettype) \
  49. CHECK_RET_CONST_DOUBLE (func, rettype) \
  50. CHECK_RET_CONST_LDOUBLE (func, rettype) \
  51. }
  52. CHECK_RET_CONST(ilogb, int)
  53. CHECK_RET_CONST(lrint, long)
  54. CHECK_RET_CONST(lround, long)
  55. CHECK_RET_CONST(llrint, long long)
  56. CHECK_RET_CONST(llround, long long)
  57. static int
  58. do_test (void)
  59. {
  60. check_return_ilogb ();
  61. check_return_lrint ();
  62. check_return_lround ();
  63. check_return_llrint ();
  64. check_return_llround ();
  65. printf ("%Zd\n", sizeof(carg (lx)));
  66. return errors != 0;
  67. }
  68. #define TEST_FUNCTION do_test ()
  69. #include "../test-skeleton.c"