external/clucene: Avoid std::string(nullptr) construction
commit396c0575b2935aeb039e8da260eba739d1a0ed3c
authorStephan Bergmann <sbergman@redhat.com>
Thu, 19 Aug 2021 14:43:59 +0000 (19 16:43 +0200)
committerStephan Bergmann <sbergman@redhat.com>
Thu, 19 Aug 2021 19:03:45 +0000 (19 21:03 +0200)
tree5ec6fe84e2754ce321f9c1d5dc5d2b2e8176d335
parent45620dc9bb3e6561fdd64e2c7d192ccae136b224
external/clucene: Avoid std::string(nullptr) construction

The relevant constructor is defined as deleted since incorporating
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2166r1.html> "A
Proposal to Prohibit std::basic_string and std::basic_string_view construction
from nullptr" into the upcoming C++23, and has caused undefined behavior in
prior versions (see the referenced document for details).  That caused

> workdir/UnpackedTarball/clucene/src/core/CLucene/index/SegmentInfos.cpp:361:13: error: conversion function from 'long' to 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char>>') invokes a deleted function
>                    return NULL;
>                           ^~~~
> ~/llvm/inst/lib/clang/14.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
> #    define NULL __null
>                  ^~~~~~
> ~/llvm/inst/bin/../include/c++/v1/string:849:5: note: 'basic_string' has been explicitly marked deleted here
>     basic_string(nullptr_t) = delete;
>     ^

at least when building --with-latest-c++ against recent libc++ 14 trunk (on
macOS).

(There might be a chance that the CLucene code naively relied on
SegmentInfo::getDelFileName actually returning a std::string for which c_str()
would return null at least at some of the call sites, which I did not inspect in
detail.  However, this would unlikely have worked in the past anyway, as it is
undefined behavior and at least contemporary libstdc++ throws a std::logic_error
when constructing a std::string from null, and at least a full `make check` with
this fix applied built fine for me.)

Change-Id: I2b8cf96b089848d666ec37aa7ee0deacc4798d35
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120745
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
external/clucene/UnpackedTarball_clucene.mk
external/clucene/patches/nullstring.patch [new file with mode: 0644]