Skip to content

Commit ccde601

Browse files
angelomatniMaskRay
authored andcommitted
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
1 parent c1909d7 commit ccde601

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

llvm/lib/ObjCopy/MachO/MachOObject.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
using namespace llvm;
1414
using namespace llvm::objcopy::macho;
1515

16+
Section::Section(StringRef SegName, StringRef SectName)
17+
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
18+
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()) {}
19+
20+
Section::Section(StringRef SegName, StringRef SectName, StringRef Content)
21+
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
22+
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()),
23+
Content(Content) {}
24+
1625
const SymbolEntry *SymbolTable::getSymbolByIndex(uint32_t Index) const {
1726
assert(Index < Symbols.size() && "invalid symbol index");
1827
return Symbols[Index].get();

llvm/lib/ObjCopy/MachO/MachOObject.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,9 @@ struct Section {
5757
StringRef Content;
5858
std::vector<RelocationInfo> Relocations;
5959

60-
Section(StringRef SegName, StringRef SectName)
61-
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
62-
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()) {}
63-
64-
Section(StringRef SegName, StringRef SectName, StringRef Content)
65-
: Segname(std::string(SegName)), Sectname(std::string(SectName)),
66-
CanonicalName((Twine(SegName) + Twine(',') + SectName).str()),
67-
Content(Content) {}
60+
Section(StringRef SegName, StringRef SectName);
61+
62+
Section(StringRef SegName, StringRef SectName, StringRef Content);
6863

6964
MachO::SectionType getType() const {
7065
return static_cast<MachO::SectionType>(Flags & MachO::SECTION_TYPE);

llvm/tools/llvm-ifs/ErrorCollector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
#ifndef LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H
2222
#define LLVM_TOOLS_LLVM_IFS_ERRORCOLLECTOR_H
2323

24+
#include "llvm/Support/Error.h"
2425
#include "llvm/Support/raw_ostream.h"
2526
#include <vector>
2627

2728
namespace llvm {
2829

29-
class Error;
30-
3130
namespace ifs {
3231

3332
class ErrorCollector {

0 commit comments

Comments
 (0)