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

via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 07:48:05 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.
----------------
sethp wrote:

I don't mean to be overly precious about this (I know I'm the one who brought limits up in the first place), but I think you're right that it kind of obscured the point here. I went for a slightly different phrasing that hopefully works for you.

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


More information about the cfe-commits mailing list