ports/devel/rapidfuzz-cpp/files/patch-fuzzing_fuzz__indel__distance.cpp
Dimitry Andric 9830c5e79d devel/rapidfuzz-cpp: fix tests with libc++ 19
As noted in the libc++ 19 release notes [1], std::char_traits<> is now
only provided for char, char8_t, char16_t, char32_t and wchar_t, and any
instantiation for other types will fail.

This causes ports using devel/rapidfuzz-cpp to fail to compile with
clang 19 and libc++ 19, resulting in errors similar to:

    /usr/include/c++/v1/string:820:42: error: implicit instantiation of undefined template 'std::char_traits<unsigned int>'
      820 |   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
          |                                          ^
    /wrkdirs/usr/ports/devel/py-rapidfuzz/work-py311/rapidfuzz-3.9.6/src/rapidfuzz/cpp_common.hpp:711:25: note: in instantiation of template class 'std::basic_string<unsigned int>' requested here
      711 |         auto proc_str = rf::opcodes_apply<uint32_t>(ops, s1, s2);
          |                         ^

The devel/rapidfuzz-cpp port itself does "build" since it only gathers a
bunch of headers and installs them into the stage area, but running
'make test' also fails similarly:

  /usr/include/c++/v1/string:820:42: error: implicit instantiation of undefined template 'std::char_traits<unsigned char>'
    820 |   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
        |                                          ^
  /wrkdirs/usr/ports/devel/rapidfuzz-cpp/work/rapidfuzz-cpp-3.0.5/test/distance/examples/ocr.cpp:3:28: note: in instantiation of template class 'std::basic_string<unsigned char>' requested here
      3 | std::basic_string<uint8_t> ocr_example1 = {
        |                            ^
  /usr/include/c++/v1/__fwd/string.h:23:29: note: template is declared here
     23 | struct _LIBCPP_TEMPLATE_VIS char_traits;
        |                             ^

Unfortunately rapidfuzz-cpp makes heavy use of the no-longer-existing
`std::basic_string<uint8_t>`, so I had to do quite a lots of search and
replace operations, replacing these with equivalent `std::vector` types.

Note that as far as I can see, only devel/py-rapidfuzz is a consumer of
this port, applying these changes should not disrupt anything else. I
have a follow-up patch for that port too.

[1] https://libcxx.llvm.org/ReleaseNotes/19.html#deprecations-and-removals

PR:		281193
Approved by:	yuri (maintainer)
MFH:		2024Q3
2024-09-02 09:45:38 +02:00

20 lines
781 B
C++

--- fuzzing/fuzz_indel_distance.cpp.orig 2024-07-02 14:50:14 UTC
+++ fuzzing/fuzz_indel_distance.cpp
@@ -8,7 +8,7 @@
#include <stdexcept>
#include <string>
-void validate_distance(const std::basic_string<uint8_t>& s1, const std::basic_string<uint8_t>& s2,
+void validate_distance(const std::vector<uint8_t>& s1, const std::vector<uint8_t>& s2,
size_t score_cutoff)
{
auto dist = rapidfuzz::indel_distance(s1, s2, score_cutoff);
@@ -25,7 +25,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* d
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
- std::basic_string<uint8_t> s1, s2;
+ std::vector<uint8_t> s1, s2;
if (!extract_strings(data, size, s1, s2)) return 0;
validate_distance(s1, s2, 0);