[all-commits] [llvm/llvm-project] 923104: Make LLVM build in C++20 mode

Barry Revzin via All-commits all-commits at lists.llvm.org
Thu Dec 17 02:49:42 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 92310454bf0f1f9686f38afd11756c7d046495c9
      https://github.com/llvm/llvm-project/commit/92310454bf0f1f9686f38afd11756c7d046495c9
  Author: Barry Revzin <barry.revzin at gmail.com>
  Date:   2020-12-17 (Thu, 17 Dec 2020)

  Changed paths:
    M clang/include/clang/AST/StmtIterator.h
    M clang/lib/Parse/ParseOpenMP.cpp
    M clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
    M llvm/include/llvm/ADT/AllocatorList.h
    M llvm/include/llvm/ADT/DenseMap.h
    M llvm/include/llvm/ADT/DenseSet.h
    M llvm/include/llvm/ADT/DirectedGraph.h
    M llvm/include/llvm/ADT/STLExtras.h
    M llvm/include/llvm/ADT/StringMap.h
    M llvm/include/llvm/ADT/iterator.h
    M llvm/include/llvm/CodeGen/DIE.h
    M llvm/include/llvm/CodeGen/LiveInterval.h
    M llvm/include/llvm/DebugInfo/DWARF/DWARFDie.h
    M llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
    M llvm/include/llvm/IR/Attributes.h
    M llvm/include/llvm/IR/BasicBlock.h
    M llvm/include/llvm/Object/StackMapParser.h
    M llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
    M llvm/include/llvm/ProfileData/InstrProfReader.h
    M llvm/include/llvm/Support/BinaryStreamRef.h
    M llvm/include/llvm/Support/SuffixTree.h
    M llvm/lib/CodeGen/PeepholeOptimizer.cpp
    M llvm/lib/IR/Attributes.cpp
    M llvm/lib/ObjectYAML/DWARFEmitter.cpp
    M llvm/lib/Transforms/Scalar/GVNHoist.cpp
    M llvm/tools/llvm-objdump/llvm-objdump.cpp
    M llvm/unittests/ADT/STLExtrasTest.cpp

  Log Message:
  -----------
  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




More information about the All-commits mailing list