2025-04-14 Paul Eggert <eggert@cs.ucla.edu>
+ regex: remove _REGEX_NELTS
+ This is a cleanup after the recent fix for undefined behavior.
+ * lib/regex.h (_REGEX_NELTS): Remove, as it is no longer useful.
+ All uses removed. Remove no-longer-needed uses of #pragma GCC.
+
regex: don’t check RE_SYNTAX_EMACS
* m4/regex.m4 (gl_REGEX): Do not check RE_SYNTAX_EMACS’s value.
Suggested by Bruno Haible in:
\f
/* Declarations for routines. */
-#ifndef _REGEX_NELTS
-/* The macro _REGEX_NELTS denotes the number of elements in a variable-length
- array passed to a function.
- It was meant to make use of ISO C99 variable-length arrays, but this does
- not work: ISO C23 § 6.7.6.2.(5) requires the number of elements to be > 0,
- but the NMATCH argument to regexec() is allowed to be 0. */
-# if 0
-# define _REGEX_NELTS(n) n
-# else
-# define _REGEX_NELTS(n)
-# endif
-#endif
-
-#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
-# pragma GCC diagnostic push
-# pragma GCC diagnostic ignored "-Wvla"
-#endif
-
#ifndef _Attr_access_
# ifdef __attr_access
# define _Attr_access_(arg) __attr_access (arg)
extern int regexec (const regex_t *_Restrict_ __preg,
const char *_Restrict_ __String, size_t __nmatch,
- regmatch_t __pmatch[_Restrict_arr_
- _REGEX_NELTS (__nmatch)],
+ regmatch_t __pmatch[_Restrict_arr_],
int __eflags);
extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
extern void regfree (regex_t *__preg);
-#if defined __GNUC__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
-# pragma GCC diagnostic pop
-#endif
-
#ifdef __cplusplus
}
#endif /* C++ */
int
regexec (const regex_t *__restrict preg, const char *__restrict string,
- size_t nmatch, regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags)
+ size_t nmatch, regmatch_t pmatch[], int eflags)
{
reg_errcode_t err;
Idx start, length;
attribute_compat_text_section
__compat_regexec (const regex_t *__restrict preg,
const char *__restrict string, size_t nmatch,
- regmatch_t pmatch[_REGEX_NELTS (nmatch)], int eflags)
+ regmatch_t pmatch[], int eflags)
{
return regexec (preg, string, nmatch, pmatch,
eflags & (REG_NOTBOL | REG_NOTEOL));