]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
preprocessor: Disable trigraphs for C2x
authorJoseph Myers <joseph@codesourcery.com>
Mon, 5 Sep 2022 22:05:06 +0000 (22:05 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Mon, 5 Sep 2022 22:05:06 +0000 (22:05 +0000)
ISO C2x removes trigraphs, so disable them accordingly for -std=c2x
(they can still be enabled using -trigraphs).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

libcpp/
* init.cc (lang_defaults): Disable trigraphs for C2x.

gcc/testsuite/
* gcc.dg/cpp/c11-trigraphs-1.c, gcc.dg/cpp/c2x-trigraphs-1.c,
gcc.dg/cpp/c2x-trigraphs-2.c: New tests.

gcc/testsuite/gcc.dg/cpp/c11-trigraphs-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/c2x-trigraphs-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/cpp/c2x-trigraphs-2.c [new file with mode: 0644]
libcpp/init.cc

diff --git a/gcc/testsuite/gcc.dg/cpp/c11-trigraphs-1.c b/gcc/testsuite/gcc.dg/cpp/c11-trigraphs-1.c
new file mode 100644 (file)
index 0000000..efd011a
--- /dev/null
@@ -0,0 +1,5 @@
+/* Test trigraphs supported in C11.  */
+/* { dg-do run } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#include "trigraphs.c"
diff --git a/gcc/testsuite/gcc.dg/cpp/c2x-trigraphs-1.c b/gcc/testsuite/gcc.dg/cpp/c2x-trigraphs-1.c
new file mode 100644 (file)
index 0000000..bbc2152
--- /dev/null
@@ -0,0 +1,10 @@
+/* Test trigraphs not supported in C2x.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic-errors" } */
+
+const char a[] = "??=??(??/??/??)??'??<??!??>??-";
+const char b[] = "?""?=?""?(?""?/?""?/?""?)?""?'?""?<?""?!?""?>?""?-";
+
+_Static_assert (sizeof a == sizeof b, "checking trigraph conversions");
+
+/* { dg-prune-output "\\\[-Wtrigraphs" } */
diff --git a/gcc/testsuite/gcc.dg/cpp/c2x-trigraphs-2.c b/gcc/testsuite/gcc.dg/cpp/c2x-trigraphs-2.c
new file mode 100644 (file)
index 0000000..38ee489
--- /dev/null
@@ -0,0 +1,5 @@
+/* Test trigraphs supported in C2x with -trigraphs used.  */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -pedantic-errors -trigraphs" } */
+
+#include "trigraphs.c"
index 41b10b3d1141c9146af6dea371def8c401129e9a..3e5601a5d962fe6afc4ef08b0ea98b72235cd147 100644 (file)
@@ -112,7 +112,7 @@ static const struct lang_flags lang_defaults[] =
   /* STDC99   */  { 1,  0,  1,  1,  0,  1,  1,   0,   0,   0,    0,     0,     1,   0,      0,   0,     0,   0,   0,      0,      0 },
   /* STDC11   */  { 1,  0,  1,  1,  1,  1,  1,   1,   0,   0,    0,     0,     1,   0,      0,   0,     0,   0,   0,      0,      0 },
   /* STDC17   */  { 1,  0,  1,  1,  1,  1,  1,   1,   0,   0,    0,     0,     1,   0,      0,   0,     0,   0,   0,      0,      0 },
-  /* STDC2X   */  { 1,  0,  1,  1,  1,  1,  1,   1,   0,   0,    1,     1,     1,   1,      0,   1,     1,   0,   1,      1,      0 },
+  /* STDC2X   */  { 1,  0,  1,  1,  1,  1,  1,   1,   0,   0,    1,     1,     0,   1,      0,   1,     1,   0,   1,      1,      0 },
   /* GNUCXX   */  { 0,  1,  1,  1,  0,  0,  1,   0,   0,   0,    0,     0,     0,   0,      1,   1,     0,   0,   0,      0,      0 },
   /* CXX98    */  { 0,  1,  0,  1,  0,  1,  1,   0,   0,   0,    0,     0,     1,   0,      0,   1,     0,   0,   0,      0,      0 },
   /* GNUCXX11 */  { 1,  1,  1,  1,  1,  0,  1,   1,   1,   1,    0,     0,     0,   0,      1,   1,     0,   0,   0,      0,      0 },