From 5f5e54157a01c540bde02c305c8ee5e1a39d4f1c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 21 Apr 2023 14:06:25 -0700 Subject: [PATCH] grep: be compatible with GNU grep -P Use PCRE2_UCP only when PCRE2_EXTRA_ASCII_BSD is defined, for compatibility with GNU grep. --- grep.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/grep.c b/grep.c index 073559f2cd..e9dc8dc0bc 100644 --- a/grep.c +++ b/grep.c @@ -320,8 +320,13 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt } options |= PCRE2_CASELESS; } - if (!opt->ignore_locale && is_utf8_locale() && !literal) - options |= (PCRE2_UTF | PCRE2_UCP | PCRE2_MATCH_INVALID_UTF); + if (!opt->ignore_locale && is_utf8_locale() && !literal) { + options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF); +#ifdef PCRE2_EXTRA_ASCII_BSD + /* Be compatible with GNU grep -P '\d'. */ + options |= (PCRE2_UCP | PCRE2_EXTRA_ASCII_BSD); +#endif + } #ifndef GIT_PCRE2_VERSION_10_35_OR_HIGHER /* -- 2.39.2