[PATCH] Small fix for tgmath.h

YunZhong Gao gaoyunzhong at gmail.com
Mon Apr 1 12:42:29 PDT 2013


  static_assert does not seem to work with C programs
  and tgmath does not seem to work with C++ programs.

  Using an array declaration works as Richard described, and
  I update my patch accordingly.

http://llvm-reviews.chandlerc.com/D595

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D595?vs=1447&id=1470#toc

Files:
  lib/Headers/tgmath.h
  test/Headers/tgmath.c

Index: lib/Headers/tgmath.h
===================================================================
--- lib/Headers/tgmath.h
+++ lib/Headers/tgmath.h
@@ -1340,15 +1340,15 @@
 
 // creal
 
-static float _Complex
+static float
     _TG_ATTRS
     __tg_creal(float __x) {return __x;}
 
-static double _Complex
+static double
     _TG_ATTRS
     __tg_creal(double __x) {return __x;}
 
-static long double _Complex
+static long double
     _TG_ATTRS
     __tg_creal(long double __x) {return __x;}
 
Index: test/Headers/tgmath.c
===================================================================
--- test/Headers/tgmath.c
+++ test/Headers/tgmath.c
@@ -0,0 +1,39 @@
+// RUN: %clang -fsyntax-only %s
+
+#include <tgmath.h>
+
+#define static_check(x) extern char dummy_array[(x) ? 1 : -1]
+
+float f;
+double d;
+long double l;
+
+float complex fc;
+double complex dc;
+long double complex lc;
+
+// creal
+
+static_check(sizeof(creal(f)) == sizeof(f));
+static_check(sizeof(creal(d)) == sizeof(d));
+static_check(sizeof(creal(l)) == sizeof(l));
+
+static_check(sizeof(creal(fc)) == sizeof(f));
+static_check(sizeof(creal(dc)) == sizeof(d));
+static_check(sizeof(creal(lc)) == sizeof(l));
+
+// fabs
+
+static_check(sizeof(fabs(f)) == sizeof(f));
+static_check(sizeof(fabs(d)) == sizeof(d));
+static_check(sizeof(fabs(l)) == sizeof(l));
+
+static_check(sizeof(fabs(fc)) == sizeof(f));
+static_check(sizeof(fabs(dc)) == sizeof(d));
+static_check(sizeof(fabs(lc)) == sizeof(l));
+
+// logb
+
+static_check(sizeof(logb(f)) == sizeof(f));
+static_check(sizeof(logb(d)) == sizeof(d));
+static_check(sizeof(logb(l)) == sizeof(l));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D595.4.patch
Type: text/x-patch
Size: 1613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130401/818a8dbe/attachment.bin>


More information about the cfe-commits mailing list