[clang] [clang-format] Correctly annotate C# UTF 8 string literals (PR #211919)

via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 26 23:54:44 PDT 2026


================
@@ -4569,6 +4569,19 @@ TEST_F(TokenAnnotatorTest, AttributeSquares) {
   EXPECT_TRUE(Tokens[15]->EndsCppAttributeGroup);
 }
 
+TEST_F(TokenAnnotatorTest, CSharpUtf8StringLiterals) {
+  const auto Style = getGoogleStyle(FormatStyle::LK_CSharp);
+  auto Tokens = annotate("var text = \"text/plain\"u8;", Style);
+
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::utf8_string_literal, TT_CSharpStringLiteral);
+
+  Tokens = annotate("var text = $\"text/plain\"u8;", Style);
----------------
owenca wrote:

```suggestion
  Tokens = annotate("var text = @\"text/plain\"u8;", Style);
```
C# doesn't allow the `u8` suffix in string interpolation.

https://github.com/llvm/llvm-project/pull/211919


More information about the cfe-commits mailing list