Skip to content

Commit

Permalink
chore: MSVC warnings fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chybz committed Jan 6, 2024
1 parent 63154e6 commit 1c02c99
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cpp/cmake/cmate
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ function(cmate_build)
cmate_state_file("configured" CONFIGURED)

if(NOT EXISTS ${CONFIGURED})
cmate_die("please configure first")
cmate_configure()
endif()

set(BUILD_DIR "${CMATE_ROOT_DIR}/build")
Expand Down
58 changes: 40 additions & 18 deletions cpp/include/gherkin/cucumber/gherkin/regex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,45 @@ extract_submatches(MatchResult&& m, Args&&... args)
}

template <
typename CharT,
typename CharT, typename Traits,
typename MatchResult
>
void
extract_submatches(
MatchResult&& m,
std::vector<std::basic_string_view<CharT>>& vs
std::vector<std::basic_string_view<CharT, Traits>>& vs
)
{
auto mit = m.begin();

while (++mit != m.end()) {
vs.push_back(std::string_view{mit->first, mit->second});
vs.push_back(
std::basic_string_view<CharT, Traits>{
mit->first,
mit->second
}
);
}
}

} // namespace detail

template <typename CharT, typename... Args>
template <
typename CharT, typename Traits,
typename ReTraits,
typename... Args>
bool
full_match(
std::basic_string_view<CharT> e,
const std::basic_regex<CharT>& re,
std::basic_string_view<CharT, Traits> e,
const std::basic_regex<CharT, ReTraits>& re,
Args&&... args
)
{
std::cmatch m;
std::match_results<const CharT*> m;
auto bit = e.data();
auto eit = e.data() + e.size();

bool match = std::regex_match(e.begin(), e.end(), m, re);
bool match = std::regex_match(bit, eit, m, re);

if (match) {
detail::extract_submatches<CharT>(m, std::forward<Args>(args)...);
Expand All @@ -145,11 +155,14 @@ full_match(
return match;
}

template <typename CharT, typename... Args>
template <
typename CharT, typename Traits,
typename... Args
>
bool
full_match(
std::basic_string_view<CharT> e,
std::basic_string_view<CharT> pat,
std::basic_string_view<CharT, Traits> e,
std::basic_string_view<CharT, Traits> pat,
Args&&... args
)
{
Expand All @@ -158,26 +171,35 @@ full_match(
return full_match(e, re, std::forward<Args>(args)...);
}

template <typename CharT, typename... Args>
template <
typename CharT, typename Traits, typename Allocator,
typename... Args
>
bool
full_match(const std::basic_string<CharT>& e, Args&&... args)
full_match(
const std::basic_string<CharT, Traits, Allocator>& e,
Args&&... args
)
{
return
full_match(
std::string_view{ e.data(), e.size() },
std::basic_string_view<CharT, Traits>{ e.data(), e.size() },
std::forward<Args>(args)...
);
}

template <typename CharT, typename... Args>
template <
typename CharT, typename Traits,
typename... Args
>
bool
partial_match(
std::basic_string_view<CharT> e,
std::basic_string_view<CharT> pat,
std::basic_string_view<CharT, Traits> e,
std::basic_string_view<CharT, Traits> pat,
Args&&... args
)
{
std::cmatch m;
std::match_results<const CharT*> m;
std::regex re(pat.data(), pat.size());

bool match = std::regex_search(e.begin(), e.end(), m, re);
Expand Down
11 changes: 11 additions & 0 deletions cpp/include/gherkin/cucumber/gherkin/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#pragma once

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#pragma warning(disable : 4244)
#endif

#include <locale>
#include <codecvt>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -255,3 +262,7 @@ struct reverse
};

}

#ifdef _MSC_VER
#pragma warning(pop)
#endif
19 changes: 19 additions & 0 deletions cpp/src/lib/gherkin/cucumber/gherkin/demangle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
// https://gist.github.com/bwoods/bbc6bd26b73fa37e94ac

#if defined(_MSC_VER)
#include <windows.h>
#include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib")
#else
#include <cxxabi.h> // gcc and clang…
#endif

#include <stdlib.h>

#include <cucumber/gherkin/demangle.hpp>
Expand All @@ -15,11 +22,23 @@ demangle(std::string&& name)
{
int status = 0;

#if defined(_MSC_VER)
//try to allocate a buffer as __cxa_demangle will do
//assuming symbol name is less than 1024 bytes
char* realname = (char*) malloc(1024 * sizeof(char));

if (realname) {
::UnDecorateSymbolName(name.c_str(), realname, 1024, 0);
}

return { realname, [] (char * p) { ::free(p); } };
#else
return
{
abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status),
[] (char * p) { ::free(p); }
};
#endif
}

} // namespace detail
Expand Down

0 comments on commit 1c02c99

Please sign in to comment.