]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Allow $@` in GNU23/GNU2Y raw string delimiters [PR110343]
authorJakub Jelinek <jakub@redhat.com>
Thu, 24 Apr 2025 13:29:50 +0000 (15:29 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 24 Apr 2025 13:29:50 +0000 (15:29 +0200)
Aaron mentioned in the PR that late in C23 N3124 was adopted and
$@` are now part of basic character set.  The paper has been implemented
in GCC from what I can see, but we should allow for GNU23/2Y $@` in
raw string delimiters as well, like they are allowed for C++26, because
the delimiters can contain anything from basic character set but space,
()\, tab, form-feed, newline and backspace.

2025-04-24  Jakub Jelinek  <jakub@redhat.com>

PR c++/110343
* lex.cc (lex_raw_string): For C allow $@` in raw string delimiters
if CPP_OPTION (pfile, low_ucns) i.e. for C23 and later.

* gcc.dg/raw-string-1.c: New test.

gcc/testsuite/gcc.dg/raw-string-1.c [new file with mode: 0644]
libcpp/lex.cc

diff --git a/gcc/testsuite/gcc.dg/raw-string-1.c b/gcc/testsuite/gcc.dg/raw-string-1.c
new file mode 100644 (file)
index 0000000..77d6145
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR c++/110343 */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu23" } */
+
+const void *s0 = R"0123456789abcdefg()0123456789abcdefg" 0;
+       /* { dg-error "raw string delimiter longer" "longer" { target *-*-* } .-1 } */
+       /* { dg-error "stray" "stray" { target *-*-* } .-2 } */
+const void *s1 = R" () " 0;
+       /* { dg-error "invalid character" "invalid" { target *-*-* } .-1 } */
+       /* { dg-error "stray" "stray" { target *-*-* } .-2 } */
+const void *s2 = R"    ()      " 0;
+       /* { dg-error "invalid character" "invalid" { target *-*-* } .-1 } */
+       /* { dg-error "stray" "stray" { target *-*-* } .-2 } */
+const void *s3 = R")())" 0;
+       /* { dg-error "invalid character" "invalid" { target *-*-* } .-1 } */
+       /* { dg-error "stray" "stray" { target *-*-* } .-2 } */
+const char *s4 = R"@()@";
+const char *s5 = R"$()$";
+const char *s6 = R"`()`";
+const void *s7 = R"\u0040()\u0040" 0;
+       /* { dg-error "invalid character" "invalid" { target *-*-* } .-1 } */
+       /* { dg-error "stray" "stray" { target *-*-* } .-2 } */
+const char *s8 = R"`@$$@`@`$()`@$$@`@`$";
+
+int main () {}
index 2d02ce6e7346a53a29d0a47492e7505ff733f9af..e7705a64f395d6f892d3a237c3da66b9a76aebce 100644 (file)
@@ -2711,8 +2711,9 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base)
                       || c == '!' || c == '=' || c == ','
                       || c == '"' || c == '\''
                       || ((c == '$' || c == '@' || c == '`')
-                          && CPP_OPTION (pfile, cplusplus)
-                          && CPP_OPTION (pfile, lang) > CLK_CXX23)))
+                          && (CPP_OPTION (pfile, cplusplus)
+                              ? CPP_OPTION (pfile, lang) > CLK_CXX23
+                              : CPP_OPTION (pfile, low_ucns)))))
            prefix[prefix_len++] = c;
          else
            {