From eed0985f87ee5c84780c4518fc28b242fa557dae Mon Sep 17 00:00:00 2001 From: "Manikandan K. S." Date: Sat, 25 Jul 2026 21:45:25 +0530 Subject: [PATCH] fix: detect macro-redefined POSIX regex symbols and fall back to SIMPLE_RE On some systems (e.g. Fedora 42 with GCC 15), MinGW or Cygwin headers leaking into the include path redefine regcomp, regexec, and regfree as macros (e.g. regcomp -> regcompA). This causes linker errors because the A-suffixed symbols do not exist in glibc. Add a compile-time check in gtest-port.h: after including , if any of regcomp, regexec, or regfree are defined as macros, undefine GTEST_USES_POSIX_RE and fall back to GTEST_USES_SIMPLE_RE instead. This leverages GoogleTest's existing simple regex implementation rather than modifying call sites. Fixes #5001 --- googletest/include/gtest/internal/gtest-port.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 31654b09c..ca0580a35 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -443,7 +443,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; #define GTEST_USES_RE2 1 #elif GTEST_HAS_POSIX_RE #include // NOLINT + +// If the POSIX regex functions have been redefined as macros (e.g., by +// MinGW headers leaking into the include path on non-Windows systems), +// the POSIX regex implementation cannot be used reliably. Fall back to +// the simple regex implementation instead. +#if defined(regcomp) || defined(regexec) || defined(regfree) +#undef GTEST_USES_POSIX_RE +#define GTEST_USES_SIMPLE_RE 1 +#else #define GTEST_USES_POSIX_RE 1 +#endif // defined(regcomp) || defined(regexec) || defined(regfree) #else // Use our own simple regex implementation. #define GTEST_USES_SIMPLE_RE 1