llvm-project/clang/lib/StaticAnalyzer/Checkers
Barry Revzin 92310454bf 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
..
MPI-Checker [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
RetainCountChecker [clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString 2020-08-05 13:54:37 +01:00
UninitializedObject [NFC] Use hasAnyName matcher in place of anyOf(hasName()...) 2020-07-07 14:31:04 +01:00
WebKit [Analyzer][WebKit] Use tri-state types for relevant predicates 2020-09-22 21:57:24 -07:00
cert [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
AllocationState.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
AnalysisOrderChecker.cpp [analyzer] Enable constructor support in evalCall event. 2020-06-25 09:47:13 -07:00
AnalyzerStatsChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ArrayBoundChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ArrayBoundCheckerV2.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
BasicObjCFoundationChecks.cpp [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it with a GDM trait 2020-09-11 15:58:48 +02:00
BlockInCriticalSectionChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
BoolAssignmentChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
BuiltinFunctionChecker.cpp Fix warning caused by __builtin_expect_with_probability was not handled 2020-07-09 08:01:33 -07:00
CMakeLists.txt [Analyzer][WebKit] UncountedLocalVarsChecker 2020-09-22 11:05:04 -07:00
CStringChecker.cpp [Analyzer] [NFC] Parameter Regions 2020-06-09 12:08:56 +02:00
CStringSyntaxChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CXXSelfAssignmentChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CallAndMessageChecker.cpp [analyzer][CallAndMessage] Add checker options for each bug type 2020-05-21 15:31:37 +02:00
CastSizeChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CastToStructChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CastValueChecker.cpp [analyzer] pr47037: CastValueChecker: Support for the new variadic isa<>. 2020-08-27 12:15:25 -07:00
CheckObjCDealloc.cpp [analyzer] Simplify function SVal::getAsSymbolicExpression and similar ones 2020-08-03 15:03:35 +03:00
CheckObjCInstMethSignature.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CheckPlacementNew.cpp [analyzer] ApiModeling: Add buffer size arg constraint 2020-05-29 16:13:57 +02:00
CheckSecuritySyntaxOnly.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CheckSizeofPointer.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CheckerDocumentation.cpp [analyzer] Fix a typo in docs 2019-01-29 10:15:52 +00:00
ChrootChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
CloneChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ContainerModeling.cpp [Analyzer] Fix for incorrect use of container and iterator checkers 2020-03-30 09:14:45 +02:00
ConversionChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
DeadStoresChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
DebugCheckers.cpp [analyzer][Liveness][NFC] Get rid of statement liveness, because such a thing doesn't exist 2020-09-15 17:43:02 +02:00
DebugContainerModeling.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
DebugIteratorModeling.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
DeleteWithNonVirtualDtorChecker.cpp [analyzer][NFC] Introduce CXXDeallocatorCall, deploy it in MallocChecker 2020-05-19 00:18:38 +02:00
DereferenceChecker.cpp [Analyzer] Improve invalid dereference bug reporting in DereferenceChecker. 2020-08-11 10:10:13 +02:00
DirectIvarAssignment.cpp [analyzer][DirectIvarAssignment] Turn DirectIvarAssignmentForAnnotatedFunctions into a checker option 2020-05-19 15:41:43 +02:00
DivZeroChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
DynamicTypeChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
DynamicTypePropagation.cpp [analyzer][ObjCGenerics] Don't emit diagnostics under the name core.DynamicTypePropagation 2020-05-20 00:19:20 +02:00
EnumCastOutOfRangeChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ExprInspectionChecker.cpp Revert "Revert "[analyzer] NFC: Move IssueHash to libAnalysis."" 2020-11-17 16:01:49 -08:00
FixedAddressChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
FuchsiaHandleChecker.cpp [analyzer] Ignore annotations if func is inlined. 2020-12-07 11:28:11 -08:00
GCDAntipatternChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
GTestChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
GenericTaintChecker.cpp Make LLVM build in C++20 mode 2020-12-17 10:44:10 +00:00
IdenticalExprChecker.cpp [OPENMP50]Add initial support for OpenMP 5.0 iterator. 2020-04-02 08:28:15 -04:00
InnerPointerChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
InterCheckerAPI.h [analyzer][MallocChecker][NFC] Communicate the allocation family to auxiliary functions with parameters 2020-02-25 11:17:32 +01:00
InvalidatedIteratorChecker.cpp [Analyzer] Handle pointer implemented as iterators in iterator checkers 2020-07-01 09:04:28 +02:00
Iterator.cpp [Analyzer] Handle pointer implemented as iterators in iterator checkers 2020-07-01 09:04:28 +02:00
Iterator.h [Analyzer] Handle pointer implemented as iterators in iterator checkers 2020-07-01 09:04:28 +02:00
IteratorModeling.cpp [analyzer] Model iterator random incrementation symmetrically 2020-08-04 11:04:12 +02:00
IteratorRangeChecker.cpp [Analyzer] Hotfix for various crashes in iterator checkers 2020-07-16 20:49:33 +02:00
IvarInvalidationChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
LLVMConventionsChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
LocalizationChecker.cpp clang/StaticAnalyzer: Stop using SourceManager::getBuffer 2020-10-15 00:34:24 -04:00
MIGChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
MacOSKeychainAPIChecker.cpp [analyzer] Simplify function SVal::getAsSymbolicExpression and similar ones 2020-08-03 15:03:35 +03:00
MacOSXAPIChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
MallocChecker.cpp [MallocChecker] Remove duplicate QCoreApplication::postEvent check. NFCI. 2020-10-27 13:14:54 +00:00
MallocOverflowSecurityChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
MallocSizeofChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
MismatchedIteratorChecker.cpp [Analyzer] Handle pointer implemented as iterators in iterator checkers 2020-07-01 09:04:28 +02:00
MmapWriteExecChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
Move.h [analyzer] PR41269: Add a bit of C++ smart pointer modeling. 2019-04-23 02:45:42 +00:00
MoveChecker.cpp [analyzer] pr47030: MoveChecker: Unforget a comma in the suppression list. 2020-08-07 10:39:28 -07:00
NSAutoreleasePoolChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
NSErrorChecker.cpp [analyzer][NSOrCFError] Don't emit diagnostics under the name osx.NSOrCFErrorDerefChecker 2020-05-20 00:05:49 +02:00
NoReturnFunctionChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
NonNullParamChecker.cpp [analyzer] Fix crash for non-pointers annotated as nonnull 2020-05-13 13:36:49 +03:00
NonnullGlobalConstantsChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
NullabilityChecker.cpp [analyzer][Nullability] Don't emit under the checker name NullabilityBase 2020-05-19 17:04:06 +02:00
NumberObjectConversionChecker.cpp [clang][NFC] Add 'override' keyword to virtual function overrides 2020-07-14 08:59:57 -07:00
OSObjectCStyleCast.cpp [analyzer] OSObjectCStyleCast: Improve warning message. 2020-12-10 19:46:33 -08:00
ObjCAtSyncChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ObjCAutoreleaseWriteChecker.cpp [analyzer] ObjCAutoreleaseWriteChecker: Support explicit autoreleasepools. 2020-06-03 19:06:04 +03:00
ObjCContainersASTChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ObjCContainersChecker.cpp [clang][NFC] Add 'override' keyword to virtual function overrides 2020-07-14 08:59:57 -07:00
ObjCMissingSuperCallChecker.cpp Upgrade SmallSets of pointer-like types to SmallPtrSet 2020-07-20 16:54:29 +02:00
ObjCPropertyChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ObjCSelfInitChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ObjCSuperDeallocChecker.cpp [analyzer] Track runtime types represented by Obj-C Class objects 2020-04-29 13:35:53 +03:00
ObjCUnusedIVarsChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
PaddingChecker.cpp [AST] Change return type of getTypeInfoInChars to a proper struct instead of std::pair. 2020-10-13 13:26:56 +02:00
PointerArithChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
PointerIterationChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
PointerSortingChecker.cpp Add some explicit use of TK_AsIs 2020-05-23 01:04:44 +01:00
PointerSubChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
PthreadLockChecker.cpp [analyzer] [NFC] Introduce refactoring of PthreadLockChecker 2020-09-08 16:04:19 +03:00
ReturnPointerRangeChecker.cpp [analyzer][ReturnPtrRangeChecker] Fix a false positive on end() iterator 2020-11-02 16:41:17 +01:00
ReturnUndefChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
ReturnValueChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
RunLoopAutoreleaseLeakChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
STLAlgorithmModeling.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
SimpleStreamChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
SmartPtr.h [Analyzer] Support note tags for smart ptr checker 2020-08-11 23:27:16 +02:00
SmartPtrChecker.cpp [Analyzer] Support note tags for smart ptr checker 2020-08-11 23:27:16 +02:00
SmartPtrModeling.cpp [Analyzer] Fix for dereferece of smart pointer after branching on unknown inner pointer 2020-10-09 13:42:25 +02:00
StackAddrEscapeChecker.cpp [analyzer][StackAddressEscape] Tie warnings to the diagnostic checkers rather then core.StackAddrEscapeBase 2020-05-20 02:26:40 +02:00
StdLibraryFunctionsChecker.cpp [analyzer][StdLibraryFunctionsChecker] Add more return value contraints 2020-12-08 17:04:29 +01:00
StreamChecker.cpp [Analyzer][StreamChecker] Use BugType::SuppressOnSink at resource leak report. 2020-07-23 11:53:25 +02:00
Taint.cpp [analyzer] Simplify function SVal::getAsSymbolicExpression and similar ones 2020-08-03 15:03:35 +03:00
Taint.h [analyzer] Add custom filter functions for GenericTaintChecker 2019-11-23 20:12:15 +01:00
TaintTesterChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
TestAfterDivZeroChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
TraversalChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
TrustNonnullChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
UndefBranchChecker.cpp [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it with a GDM trait 2020-09-11 15:58:48 +02:00
UndefCapturedBlockVarChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
UndefResultChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
UndefinedArraySubscriptChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
UndefinedAssignmentChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
UnixAPIChecker.cpp Remove llvm::Error include form Diagnostic.h 2020-04-06 10:42:17 -07:00
UnreachableCodeChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
VLASizeChecker.cpp [analyzer] Ignore calculated indices of <= 0 in VLASizeChecker 2020-06-04 07:25:35 -05:00
ValistChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
VforkChecker.cpp [analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* functions 2020-03-27 14:34:09 +01:00
VirtualCallChecker.cpp [clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString 2020-08-05 13:54:37 +01:00
Yaml.h Add some missing header dependencies 2020-02-27 14:32:12 -08:00