commit 900aa3507defd80339828e5791c215a28efd9fea
Author: Tom Honermann <tom@honermann.net>
Date: Sat Feb 13 10:02:41 2021 -0500
N2653 char8_t for C: New tests
This change provides new tests for the core language and compiler
dependent library changes proposed in WG14 N2653 for C.
Some of the tests are provided in both a positive (-fchar8_t) and
negative (-fno-char8_t) form to ensure behaviors are appropriately
present or absent in each mode.
new file mode 100644
@@ -0,0 +1,42 @@
+/* Test atomic_is_lock_free for char8_t. */
+/* { dg-do run } */
+/* { dg-options "-std=c11 -fchar8_t -pedantic-errors" } */
+
+#include <stdatomic.h>
+#include <stdint.h>
+
+extern void abort (void);
+
+_Atomic __CHAR8_TYPE__ ac8a;
+atomic_char8_t ac8t;
+
+#define CHECK_TYPE(MACRO, V1, V2) \
+ do \
+ { \
+ int r1 = MACRO; \
+ int r2 = atomic_is_lock_free (&V1); \
+ int r3 = atomic_is_lock_free (&V2); \
+ if (r1 != 0 && r1 != 1 && r1 != 2) \
+ abort (); \
+ if (r2 != 0 && r2 != 1) \
+ abort (); \
+ if (r3 != 0 && r3 != 1) \
+ abort (); \
+ if (r1 == 2 && r2 != 1) \
+ abort (); \
+ if (r1 == 2 && r3 != 1) \
+ abort (); \
+ if (r1 == 0 && r2 != 0) \
+ abort (); \
+ if (r1 == 0 && r3 != 0) \
+ abort (); \
+ } \
+ while (0)
+
+int
+main ()
+{
+ CHECK_TYPE (ATOMIC_CHAR8_T_LOCK_FREE, ac8a, ac8t);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,13 @@
+/* Test that char, signed char, and unsigned char arrays can still be
+ initialized by UTF-8 string literals if -fchar8_t is enabled. */
+/* { dg-do compile } */
+/* { dg-options "-fchar8_t" } */
+
+char cbuf1[] = u8"text";
+char cbuf2[] = { u8"text" };
+
+signed char scbuf1[] = u8"text";
+signed char scbuf2[] = { u8"text" };
+
+unsigned char ucbuf1[] = u8"text";
+unsigned char ucbuf2[] = { u8"text" };
new file mode 100644
@@ -0,0 +1,16 @@
+// Test that char8_t related predefined macros are not present when -fchar8_t is
+// not enabled.
+// { dg-do compile }
+// { dg-options "-fno-char8_t" }
+
+#if defined(_CHAR8_T_SOURCE)
+# error _CHAR8_T_SOURCE is defined!
+#endif
+
+#if defined(__CHAR8_TYPE__)
+# error __CHAR8_TYPE__ is defined!
+#endif
+
+#if defined(__GCC_ATOMIC_CHAR8_T_LOCK_FREE)
+# error __GCC_ATOMIC_CHAR8_T_LOCK_FREE is defined!
+#endif
new file mode 100644
@@ -0,0 +1,16 @@
+// Test that char8_t related predefined macros are present when -fchar8_t is
+// enabled.
+// { dg-do compile }
+// { dg-options "-fchar8_t" }
+
+#if !defined(_CHAR8_T_SOURCE)
+# error _CHAR8_T_SOURCE is not defined!
+#endif
+
+#if !defined(__CHAR8_TYPE__)
+# error __CHAR8_TYPE__ is not defined!
+#endif
+
+#if !defined(__GCC_ATOMIC_CHAR8_T_LOCK_FREE)
+# error __GCC_ATOMIC_CHAR8_T_LOCK_FREE is not defined!
+#endif
new file mode 100644
@@ -0,0 +1,6 @@
+// Test that UTF-8 string literals have type char[] if -fchar8_t is not enabled.
+// { dg-do compile }
+// { dg-options "-std=c11 -fno-char8_t" }
+
+_Static_assert (_Generic (u8"text", char*: 1, unsigned char*: 2) == 1, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], char: 1, unsigned char: 2) == 1, "UTF-8 string literal elements have an unexpected type");
new file mode 100644
@@ -0,0 +1,6 @@
+// Test that UTF-8 string literals have type unsigned char[] if -fchar8_t is enabled.
+// { dg-do compile }
+// { dg-options "-std=c11 -fchar8_t" }
+
+_Static_assert (_Generic (u8"text", char*: 1, unsigned char*: 2) == 2, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], char: 1, unsigned char: 2) == 2, "UTF-8 string literal elements have an unexpected type");