diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-07-26 15:52:23 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2021-07-29 16:16:19 +0200 |
commit | cd4bda42979cb40860a9cd2c0ed188b9a0948cd4 (patch) | |
tree | 226d8237aa351c3729389e0390662979fb606478 /gcc | |
parent | 7d014f7b224cb41e9570284d125f4c605cb0ab0a (diff) | |
download | gcc-cd4bda42979cb40860a9cd2c0ed188b9a0948cd4.zip gcc-cd4bda42979cb40860a9cd2c0ed188b9a0948cd4.tar.gz gcc-cd4bda42979cb40860a9cd2c0ed188b9a0948cd4.tar.bz2 |
d: Don't escape quoted format strings in escape_d_format (PR101656)
If the format string is enclosed by two '`' characters, then don't
escape the first and laster characters.
PR d/101656
gcc/d/ChangeLog:
* d-diagnostic.cc (escape_d_format): Don't escape quoted format
strings.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/d/d-diagnostic.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/gcc/d/d-diagnostic.cc b/gcc/d/d-diagnostic.cc index 7043abe..1982bd9 100644 --- a/gcc/d/d-diagnostic.cc +++ b/gcc/d/d-diagnostic.cc @@ -135,10 +135,21 @@ expand_d_format (const char *format) static char * escape_d_format (const char *format) { + bool quoted = false; + size_t format_len = 0; obstack buf; gcc_obstack_init (&buf); + /* If the format string is enclosed by two '`' characters, then don't escape + the first and last characters. */ + if (*format == '`') + { + format_len = strlen (format) - 1; + if (format_len && format[format_len] == '`') + quoted = true; + } + for (const char *p = format; *p; p++) { switch (*p) @@ -152,7 +163,8 @@ escape_d_format (const char *format) case '`': /* Escape '`' characters so that expand_d_format does not confuse them for a quoted string. */ - obstack_1grow (&buf, '\\'); + if (!quoted || (p != format && p != (format + format_len))) + obstack_1grow (&buf, '\\'); break; default: |