1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00
Go to file
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
benchmarks
bindings [Go] Fix bindings/go/llvm/IRBindings.cpp 2020-12-16 10:09:58 -08:00
cmake [CMake] Avoid __FakeVCSRevision.h with no git repository 2020-12-16 17:33:20 +01:00
docs [Debugify] Support checking Machine IR debug info 2020-12-16 22:17:25 -08:00
examples [Kaleidoscope] Migrate DebugInfo::get to DILocation::get 2020-12-11 18:01:04 -08:00
include Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
lib Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
projects llvmbuildectomy - replace llvm-build by plain cmake 2020-11-13 10:35:24 +01:00
resources
runtimes [runtimes] Revert the libc++ __config_site change 2020-10-23 09:41:48 -04:00
test [X86] Add X86ISD::SUBV_BROADCAST_LOAD and begin removing X86ISD::SUBV_BROADCAST (PR38969) 2020-12-17 10:25:25 +00:00
tools Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
unittests Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
utils [Debugify] Support checking Machine IR debug info 2020-12-16 22:17:25 -08:00
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt [NFC] Remove trailing whitespace in llvm/CMakeLists.txt 2020-12-14 17:48:16 +00:00
CODE_OWNERS.TXT [CODE_OWNERS.TXT] Update to include yours truly as the TableGen owner 2020-11-12 09:49:00 -05:00
configure
CREDITS.TXT [NFC] Add contributors names to CREDITS.TXT 2020-10-07 13:22:55 -04:00
LICENSE.TXT
llvm.spec.in
README.txt
RELEASE_TESTERS.TXT

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.