While testing, I discovered that master-branch grep's bootstrap script contained a regular expression with '\]' that master-branch grep now warns about. I fixed this portability bug in 'bootstrap' by installing the following patch into Gnulib and propagating this into grep master:

https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=762bd0aa660b0c1c02597e0d2e5c5fbf9bab1b91

Even though POSIX says the interpretation of \] is undefined (which means the Gnulib patch is helpful), it's unlikely that any POSIX-conforming regular expression matcher would do anything other than treat \] like plain ]. And this suggests that GNU grep's warning about \] is perhaps more trouble than it's worth.

So, what do you think of the idea of not warning for this particular stray backslash? Proposed Gnulib patch attached, with the idea of propagating this into GNU grep before its upcoming release. I haven't installed this.
From 0da5279533567c7b3470e550861643c0060e2f0d Mon Sep 17 00:00:00 2001
From: Paul Eggert <egg...@cs.ucla.edu>
Date: Fri, 3 Jun 2022 18:46:37 -0700
Subject: [PATCH] dfa: do not warn about \]
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lib/dfa.c (lex): Do not warn about \], since it’s surely
universally supported even though POSIX says its interpretation
is undefined.
---
 ChangeLog | 5 +++++
 lib/dfa.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 5fe5e9ee23..73e7898f4e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2022-06-03  Paul Eggert  <egg...@cs.ucla.edu>
 
+	dfa: do not warn about \]
+	* lib/dfa.c (lex): Do not warn about \], since it’s surely
+	universally supported even though POSIX says its interpretation
+	is undefined.
+
 	regex-quote: \] -> ] in EREs and BREs
 	* build-aux/bootstrap:
 	* build-aux/bootstrap.conf (gettext_external):
diff --git a/lib/dfa.c b/lib/dfa.c
index bd4c5f0582..d6652432a4 100644
--- a/lib/dfa.c
+++ b/lib/dfa.c
@@ -1563,6 +1563,9 @@ lex (struct dfa *dfa)
                 }
               dfawarn (msg);
             }
+          FALLTHROUGH;
+        case ']':
+          /* Do not warn about \] as that's more trouble than it's worth.  */
         normal_char:
           dfa->lex.laststart = false;
           /* For multibyte character sets, folding is done in atom.  Always
-- 
2.36.1

Reply via email to