1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/tools/llvm-objdump
Barry Revzin 2fc9f32ca3 Make LLVM build in C++20 mode
Part of the <=> changes in C++20 make certain patterns of writing equality
operators ambiguous with themselves (sorry!).
This patch goes through and adjusts all the comparison operators such that
they should work in both C++17 and C++20 modes. It also makes two other small
C++20-specific changes (adding a constructor to a type that cases to be an
aggregate, and adding casts from u8 literals which no longer have type
const char*).

There were four categories of errors that this review fixes.
Here are canonical examples of them, ordered from most to least common:

// 1) Missing const
namespace missing_const {
    struct A {
    #ifndef FIXED
        bool operator==(A const&);
    #else
        bool operator==(A const&) const;
    #endif
    };

    bool a = A{} == A{}; // error
}

// 2) Type mismatch on CRTP
namespace crtp_mismatch {
    template <typename Derived>
    struct Base {
    #ifndef FIXED
        bool operator==(Derived const&) const;
    #else
        // in one case changed to taking Base const&
        friend bool operator==(Derived const&, Derived const&);
    #endif
    };

    struct D : Base<D> { };

    bool b = D{} == D{}; // error
}

// 3) iterator/const_iterator with only mixed comparison
namespace iter_const_iter {
    template <bool Const>
    struct iterator {
        using const_iterator = iterator<true>;

        iterator();

        template <bool B, std::enable_if_t<(Const && !B), int> = 0>
        iterator(iterator<B> const&);

    #ifndef FIXED
        bool operator==(const_iterator const&) const;
    #else
        friend bool operator==(iterator const&, iterator const&);
    #endif
    };

    bool c = iterator<false>{} == iterator<false>{} // error
          || iterator<false>{} == iterator<true>{}
          || iterator<true>{} == iterator<false>{}
          || iterator<true>{} == iterator<true>{};
}

// 4) Same-type comparison but only have mixed-type operator
namespace ambiguous_choice {
    enum Color { Red };

    struct C {
        C();
        C(Color);
        operator Color() const;
        bool operator==(Color) const;
        friend bool operator==(C, C);
    };

    bool c = C{} == C{}; // error
    bool d = C{} == Red;
}

Differential revision: https://reviews.llvm.org/D78938
2020-12-17 10:44:10 +00:00
..
CMakeLists.txt [llvm-objdump][XCOFF][AIX] Implement -r option 2020-03-27 16:05:42 +00:00
COFFDump.cpp Re-land "Migrate the rest of COFFObjectFile to Error" 2020-06-11 14:46:16 -07:00
COFFDump.h [llvm-objdump][COFF][NFC] Split format-specific interfaces; add namespace 2020-04-02 18:42:13 -04:00
ELFDump.cpp [lib/Object] - Make ELFObjectFile::getSymbol() return Expected<>. 2020-12-16 13:14:23 +03:00
ELFDump.h [llvm-objdump][ELF][NFC] Create ELFDump.h 2020-04-23 21:24:37 -04:00
llvm-objdump.cpp Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
llvm-objdump.h [llvm-objdump] Implement --prefix option 2020-10-16 17:50:42 +01:00
MachODump.cpp [llvm-objdump] Use "--" for long options in --help text 2020-12-14 13:11:29 +00:00
MachODump.h [llvm-objdump][NFC] MachODump.cpp interface cleanup 2020-04-09 15:35:33 -04:00
WasmDump.cpp [llvm-objdump][Wasm][NFC] Create WasmDump.h 2020-04-14 18:26:24 -04:00
WasmDump.h [llvm-objdump][Wasm][NFC] Create WasmDump.h 2020-04-14 18:26:24 -04:00
XCOFFDump.cpp [llvm-objdump][XCOFF] Print more symbol info in relocation 2020-04-22 13:52:08 +00:00
XCOFFDump.h [llvm-objdump][XCOFF] Print more symbol info in relocation 2020-04-22 13:52:08 +00:00