Skip to content

Commit

Permalink
Restore bool T::ParseFrom(const char*, size_t) support for MSVC.
Browse files Browse the repository at this point in the history
IIRC, it was problematic for MSVC 2017 and/or MSVC 2019, but
google/oss-policies-info@dca3ce0
raised the support baseline to MSVC 2022, so let's try it...

Change-Id: Id00483381c1f6c499a2da0c2d40d235c95dedfaa
Reviewed-on: https://code-review.googlesource.com/c/re2/+/63050
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
Reviewed-by: Paul Wankadia <junyer@google.com>
  • Loading branch information
junyer committed May 13, 2024
1 parent 2b354c6 commit f31c2c6
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 8 deletions.
6 changes: 0 additions & 6 deletions re2/re2.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,14 +890,12 @@ class RE2::Arg {
re2_internal::Parse4ary<T>::value,
int>::type;

#if !defined(_MSC_VER)
template <typename T>
using CanParseFrom = typename std::enable_if<
std::is_member_function_pointer<
decltype(static_cast<bool (T::*)(const char*, size_t)>(
&T::ParseFrom))>::value,
int>::type;
#endif

public:
Arg() : Arg(nullptr) {}
Expand All @@ -909,10 +907,8 @@ class RE2::Arg {
template <typename T, CanParse4ary<T> = 0>
Arg(T* ptr) : arg_(ptr), parser_(DoParse4ary<T>) {}

#if !defined(_MSC_VER)
template <typename T, CanParseFrom<T> = 0>
Arg(T* ptr) : arg_(ptr), parser_(DoParseFrom<T>) {}
#endif

typedef bool (*Parser)(const char* str, size_t n, void* dest);

Expand All @@ -938,13 +934,11 @@ class RE2::Arg {
return re2_internal::Parse(str, n, reinterpret_cast<T*>(dest), 10);
}

#if !defined(_MSC_VER)
template <typename T>
static bool DoParseFrom(const char* str, size_t n, void* dest) {
if (dest == NULL) return true;
return reinterpret_cast<T*>(dest)->ParseFrom(str, n);
}
#endif

void* arg_;
Parser parser_;
Expand Down
2 changes: 0 additions & 2 deletions re2/testing/re2_arg_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ TEST(RE2ArgTest, Uint64Test) {
}

TEST(RE2ArgTest, ParseFromTest) {
#if !defined(_MSC_VER)
struct {
bool ParseFrom(const char* str, size_t n) {
LOG(INFO) << "str = " << str << ", n = " << n;
Expand All @@ -155,7 +154,6 @@ TEST(RE2ArgTest, ParseFromTest) {
} obj2;
RE2::Arg arg2(&obj2);
EXPECT_FALSE(arg2.Parse("two", 3));
#endif
}

TEST(RE2ArgTest, OptionalDoubleTest) {
Expand Down

0 comments on commit f31c2c6

Please sign in to comment.