Display the actual error code when RE::Init() fails PiperOrigin-RevId: 865923485 Change-Id: I5530050f7ff3fe295e2bbd7ad0dd90cd0de3e2c3
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index d50d07c..f8ecb37 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc
@@ -89,6 +89,7 @@ #include "gtest/gtest-message.h" #include "gtest/gtest-spi.h" +#include "gtest/gtest.h" #include "gtest/internal/gtest-internal.h" #include "gtest/internal/gtest-string.h" #include "src/gtest-internal-inl.h" @@ -729,7 +730,7 @@ char* const full_pattern = new char[full_regex_len]; snprintf(full_pattern, full_regex_len, "^(%s)$", regex); - is_valid_ = regcomp(&full_regex_, full_pattern, reg_flags) == 0; + int error = regcomp(&full_regex_, full_pattern, reg_flags); // We want to call regcomp(&partial_regex_, ...) even if the // previous expression returns false. Otherwise partial_regex_ may // not be properly initialized can may cause trouble when it's @@ -738,13 +739,13 @@ // Some implementation of POSIX regex (e.g. on at least some // versions of Cygwin) doesn't accept the empty string as a valid // regex. We change it to an equivalent form "()" to be safe. - if (is_valid_) { + if (!error) { const char* const partial_regex = (*regex == '\0') ? "()" : regex; - is_valid_ = regcomp(&partial_regex_, partial_regex, reg_flags) == 0; + error = regcomp(&partial_regex_, partial_regex, reg_flags); } - EXPECT_TRUE(is_valid_) - << "Regular expression \"" << regex - << "\" is not a valid POSIX Extended regular expression."; + is_valid_ = error == 0; + EXPECT_EQ(error, 0) << "Regular expression \"" << regex + << "\" is not a valid POSIX Extended regular expression."; delete[] full_pattern; }