1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00
llvm-mirror/lib
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
..
Analysis [DDG] Data Dependence Graph - DOT printer - recommit 2020-12-16 12:37:36 -05:00
AsmParser [clang][IR] Add support for leaf attribute 2020-12-14 14:48:17 -08:00
BinaryFormat [XCOFF][AIX] Emit EH information in traceback table 2020-12-16 09:34:59 -05:00
Bitcode [clang][IR] Add support for leaf attribute 2020-12-14 14:48:17 -08:00
Bitstream
CodeGen Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
DebugInfo fix typos to cycle bots 2020-12-12 20:19:33 -05:00
Demangle
DWARFLinker
ExecutionEngine [JITLink][ORC] Enable creation / linking of raw jitlink::LinkGraphs. 2020-12-16 14:01:50 +11:00
Extensions
FileCheck Use basic_string::find(char) instead of basic_string::find(const char *s, size_type pos=0) 2020-12-16 23:28:32 -08:00
Frontend [OpenMPIRBuilder] Various changes required for tileLoops. 2020-12-11 11:37:45 -06:00
Fuzzer
FuzzMutate
InterfaceStub
IR Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
IRReader
LineEditor
Linker
LTO
MC [MC][ELF] Accept abbreviated form with sh_flags and sh_entsize 2020-12-11 16:45:45 +00:00
MCA
Object [llvm-readelf/obj] - Handle out-of-order PT_LOADs better. 2020-12-16 12:59:32 +03:00
ObjectYAML Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
Option
Passes [DDG] Data Dependence Graph - DOT printer - recommit 2020-12-16 12:37:36 -05:00
ProfileData [NFC][SampleFDO] Preparation to support multiple sections with the same type 2020-12-16 22:28:45 -08:00
Remarks
Support Use basic_string::find(char) instead of basic_string::find(const char *s, size_type pos=0) 2020-12-16 23:28:32 -08:00
TableGen [TableGen] Don't dereference from dyn_cast<> - use cast<> instead. NFCI. 2020-12-14 12:12:08 +00:00
Target [X86] Add X86ISD::SUBV_BROADCAST_LOAD and begin removing X86ISD::SUBV_BROADCAST (PR38969) 2020-12-17 10:25:25 +00:00
Testing
TextAPI
ToolDrivers
Transforms Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
WindowsManifest
XRay
CMakeLists.txt