mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:43:36 +01:00
2fc9f32ca3
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 |
||
---|---|---|
.. | ||
AbstractCallSite.cpp | ||
AsmWriter.cpp | ||
Assumptions.cpp | ||
AttributeImpl.h | ||
Attributes.cpp | ||
AutoUpgrade.cpp | ||
BasicBlock.cpp | ||
CMakeLists.txt | ||
Comdat.cpp | ||
ConstantFold.cpp | ||
ConstantFold.h | ||
ConstantRange.cpp | ||
Constants.cpp | ||
ConstantsContext.h | ||
Core.cpp | ||
DataLayout.cpp | ||
DebugInfo.cpp | ||
DebugInfoMetadata.cpp | ||
DebugLoc.cpp | ||
DiagnosticHandler.cpp | ||
DiagnosticInfo.cpp | ||
DiagnosticPrinter.cpp | ||
DIBuilder.cpp | ||
Dominators.cpp | ||
FPEnv.cpp | ||
Function.cpp | ||
Globals.cpp | ||
GVMaterializer.cpp | ||
InlineAsm.cpp | ||
Instruction.cpp | ||
Instructions.cpp | ||
IntrinsicInst.cpp | ||
IRBuilder.cpp | ||
IRPrintingPasses.cpp | ||
LegacyPassManager.cpp | ||
LLVMContext.cpp | ||
LLVMContextImpl.cpp | ||
LLVMContextImpl.h | ||
LLVMRemarkStreamer.cpp | ||
Mangler.cpp | ||
MDBuilder.cpp | ||
Metadata.cpp | ||
MetadataImpl.h | ||
Module.cpp | ||
ModuleSummaryIndex.cpp | ||
Operator.cpp | ||
OptBisect.cpp | ||
Pass.cpp | ||
PassInstrumentation.cpp | ||
PassManager.cpp | ||
PassRegistry.cpp | ||
PassTimingInfo.cpp | ||
PrintPasses.cpp | ||
ProfileSummary.cpp | ||
PseudoProbe.cpp | ||
SafepointIRVerifier.cpp | ||
Statepoint.cpp | ||
StructuralHash.cpp | ||
SymbolTableListTraitsImpl.h | ||
Type.cpp | ||
TypeFinder.cpp | ||
Use.cpp | ||
User.cpp | ||
Value.cpp | ||
ValueSymbolTable.cpp | ||
Verifier.cpp |