Fix llvm/lib/ObjCopy, llvm/llvm-ifs: c++20 compatibility

Cleanup: avoid referring to `std::vector<T>` members when `T` is incomplete.

This is [not legal](https://timsong-cpp.github.io/cppwp/n4868/vector#overview-4)
according to the C++ standard, and causes build errors in particular in C++20
mode. Fix it by defining the vector's type before using the vector.

Reviewed By: saugustine, MaskRay

Differential Revision: https://reviews.llvm.org/D135906
This commit is contained in:
Angelo Matni 2022-10-14 10:28:46 -07:00 committed by Fangrui Song
parent c1909d7337
commit ccde601f14
3 changed files with 12 additions and 9 deletions

View File

@ -13,6 +13,15 @@
using namespace llvm;
using namespace llvm::objcopy::macho;
Section::Section(StringRef SegName, StringRef SectName)
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()) {}
Section::Section(StringRef SegName, StringRef SectName, StringRef Content)
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()),
Content(Content) {}
const SymbolEntry *SymbolTable::getSymbolByIndex(uint32_t Index) const {
assert(Index < Symbols.size() && "invalid symbol index");
return Symbols[Index].get();

View File

@ -57,14 +57,9 @@ struct Section {
StringRef Content;
std::vector<RelocationInfo> Relocations;
Section(StringRef SegName, StringRef SectName)
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()) {}
Section(StringRef SegName, StringRef SectName);
Section(StringRef SegName, StringRef SectName, StringRef Content)
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()),
Content(Content) {}
Section(StringRef SegName, StringRef SectName, StringRef Content);
MachO::SectionType getType() const {
return static_cast<MachO::SectionType>(Flags & MachO::SECTION_TYPE);

View File

@ -21,13 +21,12 @@
#ifndef LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H
#define LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H
#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include <vector>
namespace llvm {
class Error;
namespace ifs {
class ErrorCollector {