llvm.org GIT mirror llvm / 453f4f0
Use only explicit bool conversion operators BitVector/SmallBitVector::reference::operator bool remain implicit since they model more exactly a bool, rather than something else that can be boolean tested. The most common (non-buggy) case are where such objects are used as return expressions in bool-returning functions or as boolean function arguments. In those cases I've used (& added if necessary) a named function to provide the equivalent (or sometimes negative, depending on convenient wording) test. One behavior change (YAMLParser) was made, though no test case is included as I'm not sure how to reach that code path. Essentially any comparison of llvm::yaml::document_iterators would be invalid if neither iterator was at the end. This helped uncover a couple of bugs in Clang - test cases provided for those in a separate commit along with similar changes to `operator bool` instances in Clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181868 91177308-0d34-0410-b5e6-96231b3b80d8 David Blaikie 7 years ago
13 changed file(s) with 23 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
495495 NodeRef() {}
496496
497497 /// operator bool - Detect a null ref.
498 operator bool() const { return pip.getOpaqueValue(); }
498 LLVM_EXPLICIT operator bool() const { return pip.getOpaqueValue(); }
499499
500500 /// NodeRef - Create a reference to the node p with n elements.
501501 template
6969
7070 T *operator->() const { return Ptr; }
7171 T *get() const { return Ptr; }
72 operator bool() const { return Ptr != 0; }
72 LLVM_EXPLICIT operator bool() const { return Ptr != 0; }
7373 bool operator!() const { return Ptr == 0; }
74 bool isValid() const { return Ptr != 0; }
7475
7576 void swap(OwningPtr &RHS) {
7677 T *Tmp = RHS.Ptr;
131132 }
132133
133134 T *get() const { return Ptr; }
134 operator bool() const { return Ptr != 0; }
135 LLVM_EXPLICIT operator bool() const { return Ptr != 0; }
135136 bool operator!() const { return Ptr == 0; }
136137
137138 void swap(OwningArrayPtr &RHS) {
108108 // we recursively strip off low bits if we have a nested PointerUnion.
109109 return !PointerLikeTypeTraits::getFromVoidPointer(Val.getPointer());
110110 }
111 operator bool() const { return !isNull(); }
111 LLVM_EXPLICIT operator bool() const { return !isNull(); }
112112
113113 /// is() return true if the Union currently holds the type matching T.
114114 template
173173 return V;
174174 }
175175 };
176
177 template
178 bool operator==(PointerUnion lhs, PointerUnion rhs) {
179 return lhs.getOpaqueValue() == rhs.getOpaqueValue();
180 }
176181
177182 // Teach SmallPtrSet that PointerUnion is "basically a pointer", that has
178183 // # low bits available = min(PT1bits,PT2bits)-1.
250255 /// isNull - Return true if the pointer held in the union is null,
251256 /// regardless of which type it is.
252257 bool isNull() const { return Val.isNull(); }
253 operator bool() const { return !isNull(); }
258 LLVM_EXPLICIT operator bool() const { return !isNull(); }
254259
255260 /// is() return true if the Union currently holds the type matching T.
256261 template
358363 /// isNull - Return true if the pointer held in the union is null,
359364 /// regardless of which type it is.
360365 bool isNull() const { return Val.isNull(); }
361 operator bool() const { return !isNull(); }
366 LLVM_EXPLICIT operator bool() const { return !isNull(); }
362367
363368 /// is() return true if the Union currently holds the type matching T.
364369 template
7676 }
7777
7878 /// \brief Test whether the inline cost is low enough for inlining.
79 operator bool() const {
79 LLVM_EXPLICIT operator bool() const {
8080 return Cost < Threshold;
8181 }
8282
161161 }
162162
163163 /// Return true for a valid index.
164 operator bool() const { return isValid(); }
164 LLVM_EXPLICIT operator bool() const { return isValid(); }
165165
166166 /// Print this index to the given raw_ostream.
167167 void print(raw_ostream &os) const;
7777
7878 InstrTy *getInstruction() const { return I.getPointer(); }
7979 InstrTy *operator->() const { return I.getPointer(); }
80 operator bool() const { return I.getPointer(); }
80 LLVM_EXPLICIT operator bool() const { return I.getPointer(); }
8181
8282 /// getCalledValue - Return the pointer to function that is being called.
8383 ///
515515 if (isAtEnd() || Other.isAtEnd())
516516 return isAtEnd() && Other.isAtEnd();
517517
518 return *Doc == *Other.Doc;
518 return Doc == Other.Doc;
519519 }
520520 bool operator !=(const document_iterator &Other) {
521521 return !(*this == Other);
542542
543543 private:
544544 bool isAtEnd() const {
545 return Doc == 0 || *Doc == 0;
545 return !Doc || !*Doc;
546546 }
547547
548548 OwningPtr *Doc;
8888 AA = &getAnalysis();
8989 TD = getAnalysisIfAvailable();
9090 DT = getAnalysisIfAvailable();
91 if (PredCache == 0)
91 if (!PredCache)
9292 PredCache.reset(new PredIteratorCache());
9393 return false;
9494 }
712712 Intf.moveToBlock(BC.Number);
713713 BC.Entry = BI.LiveIn ? SpillPlacement::PrefReg : SpillPlacement::DontCare;
714714 BC.Exit = BI.LiveOut ? SpillPlacement::PrefReg : SpillPlacement::DontCare;
715 BC.ChangesValue = BI.FirstDef;
715 BC.ChangesValue = BI.FirstDef.isValid();
716716
717717 if (!Intf.hasInterference())
718718 continue;
6464 MemoryBuffer::getFile(IncludedFile.c_str(), NewBuf);
6565 }
6666
67 if (NewBuf == 0) return ~0U;
67 if (!NewBuf) return ~0U;
6868
6969 return AddNewSourceBuffer(NewBuf.take(), IncludeLoc);
7070 }
7474 }
7575
7676 // True if Handle is valid.
77 operator bool() const {
77 LLVM_EXPLICIT operator bool() const {
7878 return HandleTraits::IsValid(Handle) ? true : false;
7979 }
8080
129129 //
130130 OwningPtr PrefixOutput(ParseInputFile(BitcodeResult,
131131 BD.getContext()));
132 if (PrefixOutput == 0) {
132 if (!PrefixOutput) {
133133 errs() << BD.getToolName() << ": Error reading bitcode file '"
134134 << BitcodeResult << "'!\n";
135135 exit(1);
9797
9898 void compileAndRun(int ExpectedRC = OriginalRC) {
9999 // This function shouldn't be called until after SetUp.
100 ASSERT_TRUE(0 != TheJIT);
100 ASSERT_TRUE(TheJIT.isValid());
101101 ASSERT_TRUE(0 != Main);
102102
103103 TheJIT->finalizeObject();