aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/charlit.c
diff options
context:
space:
mode:
authorXavier Leroy <xavierleroy@users.noreply.github.com>2022-09-19 16:37:17 +0200
committerGitHub <noreply@github.com>2022-09-19 16:37:17 +0200
commit994c6c34182606385140e5695e33c90507ce59ee (patch)
treee9291d64997dd3e2ac8660c0e6fbe1b9a597799e /test/regression/charlit.c
parent103aa7074a9dd3b1bcb2864d52c89292a2ab7bff (diff)
downloadcompcert-994c6c34182606385140e5695e33c90507ce59ee.tar.gz
compcert-994c6c34182606385140e5695e33c90507ce59ee.zip
Support C11 Unicode string literals and character constants (#452)
* Support C11 Unicode string literals and character constants * Add tests for C11 string literals and character constants * Better error message for ill-formed universal character names E.g. \u followed by fewer than 4 hex digits, or \U followed by fewer than 8 hex digits. * Add new warning `invalid-utf8` for byte sequences that are not valid UTF8. The warning is activated but not fatal by default. * Warn on uses of C11 Unicode character constants and string literals This uses the `c11-extensions` warning, which is off by default. * Support preprocessing option -finput-charset= for GNU toolchains
Diffstat (limited to 'test/regression/charlit.c')
-rw-r--r--test/regression/charlit.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/regression/charlit.c b/test/regression/charlit.c
new file mode 100644
index 00000000..5a7e0916
--- /dev/null
+++ b/test/regression/charlit.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <wchar.h>
+#include <uchar.h>
+
+unsigned char c1 = 'a';
+char16_t c2 = u'a';;
+char32_t c3 = U'a';;
+wchar_t c4 = L'a';;
+
+unsigned char d1 = '\xFE';
+char16_t d2 = u'\xFE';;
+char32_t d3 = U'\xFE';;
+wchar_t d4 = L'\xFE';;
+
+unsigned char e1 = '\x1234'; // warning but no error
+char16_t e2 = u'\x1234';
+char32_t e3 = U'\x1234';
+wchar_t e4 = L'\x1234';
+
+unsigned char f1 = 'é'; // CompCert tolerance
+char16_t f2 = u'é';
+char32_t f3 = U'é';
+wchar_t f4 = L'é';
+
+unsigned char g1 = '猫'; // CompCert tolerance + warning
+char16_t g2 = u'猫';
+char32_t g3 = U'猫';
+wchar_t g4 = L'猫';
+
+unsigned char h1 = '🍌'; // CompCert tolerance + warning
+char16_t h2 = u'🍌'; // CompCert tolerance + warning
+char32_t h3 = U'🍌';
+wchar_t h4 = L'🍌';
+
+int m1 = 'ab';
+int m2 = '\x01\x02\x03\x04';
+int m3 = 'éè'; // CompCert tolerance
+
+#define PRINT(x) printf("%s: %x\n", #x, x)
+
+int main()
+{
+ PRINT(c1); PRINT(c2); PRINT(c3); PRINT(c4);
+ PRINT(d1); PRINT(d2); PRINT(d3); PRINT(d4);
+ PRINT(e1); PRINT(e2); PRINT(e3); PRINT(e4);
+ PRINT(f1); PRINT(f2); PRINT(f3); PRINT(f4);
+ PRINT(g1); PRINT(g2); PRINT(g3); PRINT(g4);
+ PRINT(h1); PRINT(h2); PRINT(h3); PRINT(h4);
+ PRINT(m1); PRINT(m2); PRINT(m3);
+}