From a368a60eb81ea6e3264e0c8c2cb12f2ee7f0585d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 21 May 2022 01:38:39 -0700 Subject: [PATCH 2/3] grep: assume POSIX.1-2017 for [:space:] * src/dfasearch.c (dfawarn): Always call dfaerror now, regardless of POSIXLY_CORRECT. * tests/warn-char-classes: Omit test of POSIX.1-2008 behavior, since POSIX.1-2017 allows the GNU behavior. --- NEWS | 3 +++ doc/grep.texi | 8 ++------ src/dfasearch.c | 8 ++------ tests/warn-char-classes | 4 ---- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index fb0e4cf..bf2ee50 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ GNU grep NEWS -*- outline -*- release 2.5.3 (2007), now warn that they are obsolescent and should be replaced by grep -E and grep -F. + Regular expressions like [:space:] are now errors even if + POSIXLY_CORRECT is set, since POSIX now allows the GNU behavior. + ** Bug fixes In locales using UTF-8 encoding, the regular expression '.' no diff --git a/doc/grep.texi b/doc/grep.texi index b073fa7..71e19e0 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -1056,8 +1056,6 @@ follow file names must be treated as file names; by default, such options are permuted to the front of the operand list and are treated as options. -Also, @env{POSIXLY_CORRECT} disables special handling of an -invalid bracket expression. @xref{invalid-bracket-expr}. @item _@var{N}_GNU_nonoption_argv_flags_ @vindex _@var{N}_GNU_nonoption_argv_flags_ @r{environment variable} @@ -1401,12 +1399,10 @@ Note that the brackets in these class names are part of the symbolic names, and must be included in addition to the brackets delimiting the bracket expression. -@anchor{invalid-bracket-expr} If you mistakenly omit the outer brackets, and search for say, @samp{[:upper:]}, GNU @command{grep} prints a diagnostic and exits with status 2, on -the assumption that you did not intend to search for the nominally -equivalent regular expression: @samp{[:epru]}. -Set the @env{POSIXLY_CORRECT} environment variable to disable this feature. +the assumption that you did not intend to search for the +regular expression @samp{[:epru]}. Special characters lose their special meaning inside bracket expressions. diff --git a/src/dfasearch.c b/src/dfasearch.c index 744b8f8..8f48296 100644 --- a/src/dfasearch.c +++ b/src/dfasearch.c @@ -53,14 +53,10 @@ dfaerror (char const *mesg) die (EXIT_TROUBLE, 0, "%s", mesg); } -/* For now, the sole dfawarn-eliciting condition (use of a regexp - like '[:lower:]') is unequivocally an error, so treat it as such, - when possible. */ -void +_Noreturn void dfawarn (char const *mesg) { - if (!getenv ("POSIXLY_CORRECT")) - dfaerror (mesg); + dfaerror (mesg); } /* If the DFA turns out to have some set of fixed strings one of diff --git a/tests/warn-char-classes b/tests/warn-char-classes index b1db240..0d87ce0 100755 --- a/tests/warn-char-classes +++ b/tests/warn-char-classes @@ -17,10 +17,6 @@ compare exp-err err || fail=1 returns_ 1 grep '[[:space:]]' x 2> err || fail=1 test -s err && fail=1 -# disabled by POSIXLY_CORRECT -returns_ 1 env POSIXLY_CORRECT=yes grep '[:space:]' x 2> err || fail=1 -test -s err && fail=1 - # patterns that are considered valid returns_ 1 grep '[::]' x 2> err || fail=1 test -s err && fail=1 -- 2.34.1