No suitable constructor exists to convert from "void" to "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>"C/C++(415)

In LLVM 9.0.0
They implemented the following code in ELFObjectWriter.cpp

void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
                                 const MCAsmLayout &Layout) {
  MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
  StringRef SectionName = Section.getSectionName();
  
  // Koo: process the special section (.rand) to store the information for transformation
  if (SectionName.startswith(".rand")) {
	std::string randContents = Asm.WriteRandInfo(Layout);
	W.OS << randContents;
    return;
  }

Here the Asm.WriteRandInfo(Layout); is resolved

What I want to do is port it to LLVM 15.0.x.
It shows the following error

no suitable constructor exists to convert from "void" to "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>"C/C++(415)

The error message means you’re trying to use a “void” return value to construct a string.