[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#57604: [ef]grep usage -> POSIXLY_CORRECT?

From: Jim Meyering
Subject: bug#57604: [ef]grep usage -> POSIXLY_CORRECT?
Date: Thu, 8 Sep 2022 02:21:42 -0700

Hi Karl,

Sorry to cause you grief, but...

On Wed, Sep 7, 2022 at 7:49 PM Karl Berry <karl@freefriends.org> wrote:
>     [ef]grep
> I guess my basic issue is that I don't understand the benefit of the new
> warning.  It causes a lot of trouble.  What is the countervailing
> positive benefit?

Some must care about portability, and these warnings help them do a better job.
As Gary mentioned above, it's easy to disable them.

>     $ grep '\Q' /dev/null
>     grep: warning: stray \ before Q

> It would be nice to be able to turn those off too. (It hit me today.)

I would argue that it is even more important to retain these
stray-backslash warnings, because they tend to highlight real bugs.
Consider these uses of \d:

  $ echo d | grep-3.7 '\d'
  $ echo d | grep-3.8 '\d'
  grep: warning: stray \ before d

Anyone used to PCRE regexps (who isn't, these days) knows that its
"\d" is intended to match a digit, not the letter "d". With grep-3.7,
you'd get misbehavior and no warning about your error. With grep-3.8,
you'll get the diagnostic and maybe switch to using "grep -P", where
"\d" works as expected -- switching from \d to [0-9] hurts readability
and feels like dumbing-down, especially when there are two or more \d
uses. Using PCRE's \Q...\E groups *without -P* is another issue that
is now diagnosed.

For example, the following upstream projects have misuses of grep that
are exposed by running this:

  git grep 'grep .*\\[dQE]' | grep -ve '-[[:alnum:]]*P'

- linux
scripts/checkpatch.pl:          `grep -Eq
"\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;

- gcc
'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod
libgo/go/cmd/go/testdata/script/mod_get_lazy_indirect.txt:! grep
'rsc.io/quote v\d+\.\d+\.\d+$' go.mod
'rsc.io/quote v\d+\.\d+\.\d+$' go.mod
libgo/go/cmd/go/testdata/script/mod_get_lazy_indirect.txt:! grep
'rsc.io/quote v\d+\.\d+\.\d+ // indirect$' go.mod

reply via email to

[Prev in Thread] Current Thread [Next in Thread]