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

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 14 10:28:56 PDT 2022


Author: Angelo Matni
Date: 2022-10-14T10:28:46-07:00
New Revision: ccde601f140c79344e67e3a5164524ea3d8f43aa

URL: https://github.com/llvm/llvm-project/commit/ccde601f140c79344e67e3a5164524ea3d8f43aa
DIFF: https://github.com/llvm/llvm-project/commit/ccde601f140c79344e67e3a5164524ea3d8f43aa.diff

LOG: 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

Added: 
    

Modified: 
    llvm/lib/ObjCopy/MachO/MachOObject.cpp
    llvm/lib/ObjCopy/MachO/MachOObject.h
    llvm/tools/llvm-ifs/ErrorCollector.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ObjCopy/MachO/MachOObject.cpp b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
index 56f31e456198f..1303d6685d523 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.cpp
@@ -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();

diff  --git a/llvm/lib/ObjCopy/MachO/MachOObject.h b/llvm/lib/ObjCopy/MachO/MachOObject.h
index df9261b76e4d5..15877eff33b03 100644
--- a/llvm/lib/ObjCopy/MachO/MachOObject.h
+++ b/llvm/lib/ObjCopy/MachO/MachOObject.h
@@ -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, StringRef Content)
-      : Segname(std::string(SegName)), Sectname(std::string(SectName)),
-        CanonicalName((Twine(SegName) + Twine(',') + SectName).str()),
-        Content(Content) {}
+  Section(StringRef SegName, StringRef SectName);
+
+  Section(StringRef SegName, StringRef SectName, StringRef Content);
 
   MachO::SectionType getType() const {
     return static_cast<MachO::SectionType>(Flags & MachO::SECTION_TYPE);

diff  --git a/llvm/tools/llvm-ifs/ErrorCollector.h b/llvm/tools/llvm-ifs/ErrorCollector.h
index d3a814b94ae7a..2b91e905bcda4 100644
--- a/llvm/tools/llvm-ifs/ErrorCollector.h
+++ b/llvm/tools/llvm-ifs/ErrorCollector.h
@@ -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 {


        


More information about the llvm-commits mailing list