c++: Test for mixed string literal concatenation
authorJason Merrill <jason@redhat.com>
Tue, 8 Jun 2021 18:38:42 +0000 (14:38 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 8 Jun 2021 19:34:43 +0000 (15:34 -0400)
From wg21.link/p2201r1

gcc/cp/ChangeLog:

* parser.c (cp_parser_string_literal): Adjust diagnostic.

gcc/testsuite/ChangeLog:

* g++.dg/cpp23/mixed-concat1.C: New test.

gcc/cp/parser.c
gcc/testsuite/g++.dg/cpp23/mixed-concat1.C [new file with mode: 0644]

index 24f248a..d59a829 100644 (file)
@@ -4378,8 +4378,8 @@ cp_parser_string_literal (cp_parser *parser, bool translate, bool wide_ok,
                  rich_location rich_loc (line_table, tok->location);
                  rich_loc.add_range (last_tok_loc);
                  error_at (&rich_loc,
-                           "unsupported non-standard concatenation "
-                           "of string literals");
+                           "concatenation of string literals with "
+                           "conflicting encoding prefixes");
                }
            }
 
diff --git a/gcc/testsuite/g++.dg/cpp23/mixed-concat1.C b/gcc/testsuite/g++.dg/cpp23/mixed-concat1.C
new file mode 100644 (file)
index 0000000..d69fafc
--- /dev/null
@@ -0,0 +1,21 @@
+// Test from P2201R1
+// { dg-do compile { target c++11 } }
+
+void f() {
+
+  { auto a = L"" u""; }                // { dg-error "concatenation" }
+  { auto a = L"" u8""; }       // { dg-error "concatenation" }
+  { auto a = L"" U""; }                // { dg-error "concatenation" }
+
+  { auto a = u8"" L""; }       // { dg-error "concatenation" }
+  { auto a = u8"" u""; }       // { dg-error "concatenation" }
+  { auto a = u8"" U""; }       // { dg-error "concatenation" }
+
+  { auto a = u"" L""; }                // { dg-error "concatenation" }
+  { auto a = u"" u8""; }       // { dg-error "concatenation" }
+  { auto a = u"" U""; }                // { dg-error "concatenation" }
+
+  { auto a = U"" L""; }                // { dg-error "concatenation" }
+  { auto a = U"" u""; }                // { dg-error "concatenation" }
+  { auto a = U"" u8""; }       // { dg-error "concatenation" }
+}