[clang] [Clang] Wide delimiters ('{{{') for expect strings (PR #77326)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 11:02:44 PST 2024


================
@@ -3458,8 +3461,34 @@ A range can also be specified by ``<n>-<m>``. For example:
 
 In this example, the diagnostic may appear only once, if at all.
 
+.. _DiagnosticMatching:
+
+Matching Modes
+~~~~~~~~~~~~~~
+
+The default matching mode is simple string, which looks for the expected text
+that appears between the first `{{` and `}}` pair of the comment. The string is
+interpreted just as-is, with one exception: the sequence `\n` is converted to a
+single newline character. This mode matches the emitted diagnostic when the
+text appears as a substring at any position of the emitted message.
+
+To enable matching against desired strings that contain `}}` or `{{`, the
+string-mode parser accepts opening delimiters of more than two curly braces,
+like `{{{`. It then looks for a closing delimiter of equal "width" (i.e `}}}`).
+For example:
+
+.. code-block:: c++
+
+  // expected-note {{{evaluates to '{{2, 3, 4}} == {0, 3, 4}'}}}
+
+If your expected text contains `{{{` (three braces), then it may be delimited
+with `{{{{` (four braces), and so on. If your expected text contains enough
+repeated `{`s to fill up a `ptrdiff_t`, then you'll definitely crash the
+parser, possibly even as late as the delimiter handling.
----------------
erichkeane wrote:

Perhaps "There is no limit to the width of a delimiter", else SGTM.

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


More information about the cfe-commits mailing list