shithub: scc

Download patch

ref: 1b51b30c2d7d831f8e8ef83b254fe6cd2052ff89
parent: 3e5e7c470c58ff0b76e6cabc83691897ca4d4e93
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Mar 22 05:05:47 EDT 2022

tests/cc: Add test 0189-cpp.c

--- /dev/null
+++ b/tests/cc/execute/0189-cpp.c
@@ -1,0 +1,97 @@
+/* taken from ISO/IEC 9899:1999 Section 6.10.3.5 p5 */
+
+int z[3] = {1, 0, 0};
+
+int
+f(int x)
+{
+	return x+1;
+}
+
+int
+t(int x)
+{
+	return x+2;
+}
+
+int
+m(int x, int y)
+{
+	return x+y;
+}
+
+#define    x          3
+#define    f(a)       f(x * (a))
+#undef     x
+
+#define    x          2
+#define    z          z[0]
+#define    g          f
+#define    h          g(~
+#define    m(a)       a(w)
+#define    w          0,1
+#define    t(a)       a
+#define    p()        int
+#define    q(x)       x
+#define    r(x,y)     x ## y
+#define    str(x)     # x
+
+int
+test1()
+{
+	return f(z) == 3;
+}
+
+int
+test2(int y)
+{
+	return f(y+1) + f(f(z)) % t(t(g)(0) + t)(1) == 10;
+}
+
+int
+test3()
+{
+	return g(x+(3,4)-w) | h 5) & m
+		(f)^m(m) == 3;
+}
+
+int
+test4()
+{
+	p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };
+
+	return i[0] + i[1] + i[2] + i[3] == 33;
+}
+
+int
+test5()
+{
+	int i;
+	char c[2][6] = { str(hello), str() };
+
+	for (i = 0; i < 6; i++) {
+		if (c[0][i] != "hello"[i])
+			return 0;
+	}
+
+	if (c[1][0] != '\0')
+		return 0;
+
+	return 1;
+}
+
+int
+main()
+{
+	if (!test1())
+		return 1;
+	if (!test2(2))
+		return 2;
+	if (!test3())
+		return 3;
+	if (!test4())
+		return 4;
+	if (!test5())
+		return 5;
+	return 0;
+}
--- a/tests/cc/execute/scc-tests.lst
+++ b/tests/cc/execute/scc-tests.lst
@@ -179,6 +179,7 @@
 0186-dec-ary.c
 0187-zero-struct.c
 0188-multi-string.c [TODO]
+0189-cpp.c [TODO]
 0190-enum-ary.c
 0191-ary-addr.c
 0192-ptrcmp.c