]> granicus.if.org Git - clang/commitdiff
Use only explicit bool conversion operator
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 15 May 2013 07:37:26 +0000 (07:37 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 15 May 2013 07:37:26 +0000 (07:37 +0000)
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.

DiagnosticBuilder kept its implicit conversion operator owing to the
prevalent use of it in return statements.

One bug was found in ExprConstant.cpp involving a comparison of two
PointerUnions (PointerUnion did not previously have an operator==, so
instead both operands were converted to bool & then compared). A test
is included in test/SemaCXX/constant-expression-cxx1y.cpp for the fix
(adding operator== to PointerUnion in LLVM).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181869 91177308-0d34-0410-b5e6-96231b3b80d8

45 files changed:
include/clang/AST/CanonicalType.h
include/clang/AST/DeclFriend.h
include/clang/AST/DeclObjC.h
include/clang/AST/DeclarationName.h
include/clang/AST/ExprCXX.h
include/clang/AST/ExternalASTSource.h
include/clang/AST/NestedNameSpecifier.h
include/clang/AST/StmtIterator.h
include/clang/AST/Type.h
include/clang/AST/TypeLoc.h
include/clang/Analysis/Analyses/FormatString.h
include/clang/Analysis/CFG.h
include/clang/Basic/Diagnostic.h
include/clang/Frontend/ASTUnit.h
include/clang/Frontend/CompilerInstance.h
include/clang/Frontend/FrontendAction.h
include/clang/Lex/HeaderSearch.h
include/clang/Lex/MacroInfo.h
include/clang/Lex/ModuleMap.h
include/clang/Lex/Preprocessor.h
include/clang/Sema/Initialization.h
include/clang/Sema/Ownership.h
include/clang/Sema/Sema.h
include/clang/Sema/TypoCorrection.h
include/clang/Serialization/ASTReader.h
include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
include/clang/StaticAnalyzer/Core/Checker.h
include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
lib/AST/ASTDumper.cpp
lib/AST/ASTImporter.cpp
lib/AST/Decl.cpp
lib/AST/Expr.cpp
lib/AST/ExprConstant.cpp
lib/Analysis/CFG.cpp
lib/CodeGen/CodeGenFunction.h
lib/Lex/HeaderMap.cpp
lib/Lex/PPDirectives.cpp
lib/Lex/PPLexerChange.cpp
lib/Parse/ParseDecl.cpp
lib/Rewrite/Core/Rewriter.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
test/SemaCXX/constant-expression-cxx1y.cpp
unittests/Tooling/CompilationDatabaseTest.cpp

index 946075739d061e82ea6c9cb1ac08183f5dd2e85f..9c699b7e0ae2fd1b6365047224fc97816ce026b9 100644 (file)
@@ -81,7 +81,7 @@ public:
   operator QualType() const { return Stored; }
 
   /// \brief Implicit conversion to bool.
-  operator bool() const { return !isNull(); }
+  LLVM_EXPLICIT operator bool() const { return !isNull(); }
   
   bool isNull() const {
     return Stored.isNull();
index 3a12878e7414f2a2169cb8e35a5fbbc6001ccc58..589178ec6ec368dedf7290b91e46411e5bdbda96 100644 (file)
@@ -228,7 +228,7 @@ inline CXXRecordDecl::friend_iterator CXXRecordDecl::friend_end() const {
 }
 
 inline void CXXRecordDecl::pushFriendDecl(FriendDecl *FD) {
-  assert(FD->NextFriend == 0 && "friend already has next friend?");
+  assert(!FD->NextFriend && "friend already has next friend?");
   FD->NextFriend = data().FirstFriend;
   data().FirstFriend = FD;
 }
index 40de0135a74f693b5fe29d6005e016f23bc5cca5..0028240349ae18dd4eabc62c0833908245018742 100644 (file)
@@ -452,7 +452,7 @@ public:
   }
 
   /// \brief Determine whether this method has a body.
-  virtual bool hasBody() const { return Body; }
+  virtual bool hasBody() const { return Body.isValid(); }
 
   /// \brief Retrieve the body of this method, if it has one.
   virtual Stmt *getBody() const;
@@ -463,7 +463,7 @@ public:
   void setBody(Stmt *B) { Body = B; }
 
   /// \brief Returns whether this specific method is a definition.
-  bool isThisDeclarationADefinition() const { return Body; }
+  bool isThisDeclarationADefinition() const { return hasBody(); }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
index e01b80f3896a8bc0f5d96ea17bc83f4752f1d3ba..00766c27c136c0cc44beccada05109e5220f25e7 100644 (file)
@@ -182,11 +182,16 @@ public:
 
   // operator bool() - Evaluates true when this declaration name is
   // non-empty.
-  operator bool() const {
+  LLVM_EXPLICIT operator bool() const {
     return ((Ptr & PtrMask) != 0) ||
            (reinterpret_cast<IdentifierInfo *>(Ptr & ~PtrMask));
   }
 
+  /// \brief Evaluates true when this declaration name is empty.
+  bool isEmpty() const {
+    return !*this;
+  }
+
   /// Predicate functions for querying what type of name this is.
   bool isIdentifier() const { return getStoredNameKind() == StoredIdentifier; }
   bool isObjCZeroArgSelector() const {
index 91e5b21eacffcf21813b48e13eaecc29911af6a1..a4f296c988f61a1e1c600b4b71da16a8a9090e41 100644 (file)
@@ -1935,7 +1935,7 @@ public:
   /// \brief Determines whether this member expression actually had
   /// a C++ nested-name-specifier prior to the name of the member, e.g.,
   /// x->Base::foo.
-  bool hasQualifier() const { return QualifierLoc; }
+  bool hasQualifier() const { return QualifierLoc.hasQualifier(); }
 
   /// \brief Retrieves the nested-name-specifier that qualifies the type name,
   /// with source-location information.
index 81fcf242b65eaddbd666ce62735b9eaa2b2c9357..b077426e6a479d865ca48288ef3d194b9739406f 100644 (file)
@@ -329,7 +329,12 @@ public:
   /// \brief Whether this pointer is non-NULL.
   ///
   /// This operation does not require the AST node to be deserialized.
-  operator bool() const { return Ptr != 0; }
+  LLVM_EXPLICIT operator bool() const { return Ptr != 0; }
+
+  /// \brief Whether this pointer is non-NULL.
+  ///
+  /// This operation does not require the AST node to be deserialized.
+  bool isValid() const { return Ptr != 0; }
 
   /// \brief Whether this pointer is currently stored as an offset.
   bool isOffset() const { return Ptr & 0x01; }
index 58f39862b10228834a3b54d1ffc8b68136cf7073..b332b153fe8d0dca906001b1c8735e3f454d16cb 100644 (file)
@@ -231,7 +231,11 @@ public:
 
   /// \brief Evalutes true when this nested-name-specifier location is
   /// non-empty.
-  operator bool() const { return Qualifier; }
+  LLVM_EXPLICIT operator bool() const { return Qualifier; }
+
+  /// \brief Evalutes true when this nested-name-specifier location is
+  /// empty.
+  bool hasQualifier() const { return Qualifier; }
 
   /// \brief Retrieve the nested-name-specifier to which this instance
   /// refers.
index b933ed0762603ee75ff301a54e9e84475a477399..fc25fa9a6e6c1b3964116905a6ed51362cf3b8ea 100644 (file)
@@ -15,6 +15,7 @@
 #define LLVM_CLANG_AST_STMT_ITR_H
 
 #include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Compiler.h"
 #include <cassert>
 #include <cstddef>
 #include <iterator>
@@ -156,7 +157,7 @@ struct StmtRange : std::pair<StmtIterator,StmtIterator> {
     : std::pair<StmtIterator,StmtIterator>(begin, end) {}
 
   bool empty() const { return first == second; }
-  operator bool() const { return !empty(); }
+  LLVM_EXPLICIT operator bool() const { return !empty(); }
 
   Stmt *operator->() const { return first.operator->(); }
   Stmt *&operator*() const { return first.operator*(); }
@@ -199,7 +200,7 @@ struct ConstStmtRange : std::pair<ConstStmtIterator,ConstStmtIterator> {
     : std::pair<ConstStmtIterator,ConstStmtIterator>(begin, end) {}
 
   bool empty() const { return first == second; }
-  operator bool() const { return !empty(); }
+  LLVM_EXPLICIT operator bool() const { return !empty(); }
 
   const Stmt *operator->() const { return first.operator->(); }
   const Stmt *operator*() const { return first.operator*(); }
index 39f10d3393bac57773db7eb58e4641ffdeff0ac7..93c287fd18c6716f5d88e1713e9b0abd2c731e6e 100644 (file)
@@ -441,7 +441,7 @@ public:
   bool operator==(Qualifiers Other) const { return Mask == Other.Mask; }
   bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; }
 
-  operator bool() const { return hasQualifiers(); }
+  LLVM_EXPLICIT operator bool() const { return hasQualifiers(); }
 
   Qualifiers &operator+=(Qualifiers R) {
     addQualifiers(R);
index 11cad9bb9dd97d1b4beeb8e0e6f0d126ec4a9f9b..9e2d3bffb93dceddf7f2da5b3cd8f9bdcaba40c0 100644 (file)
@@ -90,7 +90,7 @@ public:
   }
 
   bool isNull() const { return !Ty; }
-  operator bool() const { return Ty; }
+  LLVM_EXPLICIT operator bool() const { return Ty; }
 
   /// \brief Returns the size of type source info data block for the given type.
   static unsigned getFullDataSizeForType(QualType Ty);
index 4bd989cf4ef314657cb9b5808d2e08dbc3f898ee..6ad89aec0a3ffc01e893dfca2edd236e9d0aa724 100644 (file)
@@ -49,7 +49,7 @@ public:
   const char *toString() const { return representation; }
 
   // Overloaded operators for bool like qualities
-  operator bool() const { return flag; }
+  LLVM_EXPLICIT operator bool() const { return flag; }
   OptionalFlag& operator=(const bool &rhs) {
     flag = rhs;
     return *this;  // Return a reference to myself.
index ee0be736dd5ed2d9f3d828892073849fa1eef506..01480ed3b45221708788d2d7d786bb1d5f08b5dc 100644 (file)
@@ -269,7 +269,7 @@ public:
   Stmt &operator*() { return *getStmt(); }
   const Stmt &operator*() const { return *getStmt(); }
 
-  operator bool() const { return getStmt(); }
+  LLVM_EXPLICIT operator bool() const { return getStmt(); }
 };
 
 /// CFGBlock - Represents a single basic block in a source-level CFG.
index 3e125944a36164f1345abd301304ecff305e7eb4..1354120ea59f29ae9bd42604ee4b87b6c98c09fa 100644 (file)
@@ -1212,7 +1212,7 @@ public:
   ~StoredDiagnostic();
 
   /// \brief Evaluates true when this object stores a diagnostic.
-  operator bool() const { return Message.size() > 0; }
+  LLVM_EXPLICIT operator bool() const { return Message.size() > 0; }
 
   unsigned getID() const { return ID; }
   DiagnosticsEngine::Level getLevel() const { return Level; }
index 9bd0ef31e09b6b763bd45dbc72b8ea99c4166b57..1fc56ce5f3ca22be61c2157ee7c4c4101db0ddd1 100644 (file)
@@ -456,7 +456,7 @@ public:
   void setASTContext(ASTContext *ctx) { Ctx = ctx; }
   void setPreprocessor(Preprocessor *pp);
 
-  bool hasSema() const { return TheSema; }
+  bool hasSema() const { return TheSema.isValid(); }
   Sema &getSema() const { 
     assert(TheSema && "ASTUnit does not have a Sema object!");
     return *TheSema; 
index dbd76066b94e0bf477bff9503a117e6cd3e33a50..ee4850580d660936704efbb2960f27ec4f3acda3 100644 (file)
@@ -395,7 +395,7 @@ public:
   /// @name ASTConsumer
   /// {
 
-  bool hasASTConsumer() const { return Consumer != 0; }
+  bool hasASTConsumer() const { return Consumer.isValid(); }
 
   ASTConsumer &getASTConsumer() const {
     assert(Consumer && "Compiler instance has no AST consumer!");
@@ -413,7 +413,7 @@ public:
   /// }
   /// @name Semantic analysis
   /// {
-  bool hasSema() const { return TheSema != 0; }
+  bool hasSema() const { return TheSema.isValid(); }
   
   Sema &getSema() const { 
     assert(TheSema && "Compiler instance has no Sema object!");
@@ -433,7 +433,9 @@ public:
   /// @name Code Completion
   /// {
 
-  bool hasCodeCompletionConsumer() const { return CompletionConsumer != 0; }
+  bool hasCodeCompletionConsumer() const {
+    return CompletionConsumer.isValid();
+  }
 
   CodeCompleteConsumer &getCodeCompletionConsumer() const {
     assert(CompletionConsumer &&
@@ -455,7 +457,7 @@ public:
   /// @name Frontend timer
   /// {
 
-  bool hasFrontendTimer() const { return FrontendTimer != 0; }
+  bool hasFrontendTimer() const { return FrontendTimer.isValid(); }
 
   llvm::Timer &getFrontendTimer() const {
     assert(FrontendTimer && "Compiler instance has no frontend timer!");
index c67be924720c68779f458f2e81ad155d9556cdc6..fee8d95a05ba8bdf55d3c0b104668930df898c2a 100644 (file)
@@ -116,7 +116,7 @@ public:
 
   bool isCurrentFileAST() const {
     assert(!CurrentInput.isEmpty() && "No current file!");
-    return CurrentASTUnit != 0;
+    return CurrentASTUnit.isValid();
   }
 
   const FrontendInputFile &getCurrentInput() const {
index c46c8ce6ef019eb2d2b91ec5bdb6b0c19a3c9b6b..498de0949686e5ac64e9f2a8978e4e0bc6303709 100644 (file)
@@ -264,7 +264,7 @@ public:
 
   /// \brief Checks whether the map exists or not.
   bool HasIncludeAliasMap() const {
-    return IncludeAliases;
+    return IncludeAliases.isValid();
   }
 
   /// \brief Map the source include name to the dest include name.
index 64323b7c765f580bba05939e5bff3b9d7ec39a06..b4ce4db7ddfca23fd847cce4445c1a6b8e28dca0 100644 (file)
@@ -421,7 +421,7 @@ public:
     bool isValid() const { return DefDirective != 0; }
     bool isInvalid() const { return !isValid(); }
 
-    operator bool() const { return isValid(); }
+    LLVM_EXPLICIT operator bool() const { return isValid(); }
 
     inline DefInfo getPreviousDefinition(bool AllowHidden = false);
     const DefInfo getPreviousDefinition(bool AllowHidden = false) const {
index 9fe97d01110bead3d15ffa91bf2b45983c8aad7a..bd57ce487725cc5e6c93bcf006b6feda0816b0b9 100644 (file)
@@ -80,7 +80,7 @@ class ModuleMap {
 
     // \brief Whether this known header is valid (i.e., it has an
     // associated module).
-    operator bool() const { return Storage.getPointer() != 0; }
+    LLVM_EXPLICIT operator bool() const { return Storage.getPointer() != 0; }
   };
 
   typedef llvm::DenseMap<const FileEntry *, KnownHeader> HeadersMap;
index c5981777cd291a3e84b8ee71a4b402bbb3637cdf..89cb696f62a591bdad346eef6b1fedd5eb74512b 100644 (file)
@@ -1400,7 +1400,7 @@ private:
   bool InCachingLexMode() const {
     // If the Lexer pointers are 0 and IncludeMacroStack is empty, it means
     // that we are past EOF, not that we are in CachingLex mode.
-    return CurPPLexer == 0 && CurTokenLexer == 0 && CurPTHLexer == 0 &&
+    return !CurPPLexer && !CurTokenLexer && !CurPTHLexer &&
            !IncludeMacroStack.empty();
   }
   void EnterCachingLexMode();
index 58781ac628c404f796e269615bfb763e0edcb15e..3f70672459f07ab38b1a6723f0ecea554f694462 100644 (file)
@@ -841,7 +841,7 @@ public:
   void setSequenceKind(enum SequenceKind SK) { SequenceKind = SK; }
   
   /// \brief Determine whether the initialization sequence is valid.
-  operator bool() const { return !Failed(); }
+  LLVM_EXPLICIT operator bool() const { return !Failed(); }
 
   /// \brief Determine whether the initialization sequence is invalid.
   bool Failed() const { return SequenceKind == FailedSequence; }
index c3d1f4e0b7dbe6eefb6da5e4d6713e05a82e6eef..92c486db36fea1d76e192eff3f8d5a79f03197e6 100644 (file)
@@ -65,7 +65,7 @@ namespace clang {
       Ptr = Traits::getAsVoidPointer(P);
     }
 
-    operator bool() const { return Ptr != 0; }
+    LLVM_EXPLICIT operator bool() const { return Ptr != 0; }
 
     void *getAsOpaquePtr() const { return Ptr; }
     static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
index c2300e977e8606dee3cf2b2138b390e67973d139..61b91c596257aa538cf052567ec38e17c3aef43d 100644 (file)
@@ -5994,7 +5994,7 @@ public:
 
     /// \brief Determines whether we have exceeded the maximum
     /// recursive template instantiations.
-    operator bool() const { return Invalid; }
+    LLVM_EXPLICIT operator bool() const { return Invalid; }
 
   private:
     Sema &SemaRef;
index 5fbfba2d5d0e88af13ec23cbda3739485801aae3..59f34176056ac8ca12de6226371649e92fdced89 100644 (file)
@@ -140,7 +140,7 @@ public:
   }
 
   /// \brief Returns whether this TypoCorrection has a non-empty DeclarationName
-  operator bool() const { return bool(CorrectionName); }
+  LLVM_EXPLICIT operator bool() const { return bool(CorrectionName); }
 
   /// \brief Mark this TypoCorrection as being a keyword.
   /// Since addCorrectionDeclsand setCorrectionDecl don't allow NULL to be
index bb59784dff96fbde917824a6935cd71ba601adfb..073baf514cd3bc779342a8f8c9037024a2f19407 100644 (file)
@@ -1232,7 +1232,7 @@ public:
   void setDeserializationListener(ASTDeserializationListener *Listener);
 
   /// \brief Determine whether this AST reader has a global index.
-  bool hasGlobalIndex() const { return GlobalIndex; }
+  bool hasGlobalIndex() const { return GlobalIndex.isValid(); }
 
   /// \brief Attempts to load the global index.
   ///
index a80b5a7a248ce086efbd0f0b5ce2ecb7ad675d47..09ee005af721c3925103101b7595cd72311f8043 100644 (file)
@@ -504,7 +504,7 @@ public:
   }
   
   bool hasCallStackHint() {
-    return (CallStackHint != 0);
+    return CallStackHint.isValid();
   }
 
   /// Produce the hint for the given node. The node contains 
index 0dbaab033d2dd3cdf2b530567f16767b074d16ae..d56f8e9c1d4e847ec582a368605428d2d971586d 100644 (file)
@@ -505,7 +505,7 @@ struct ImplicitNullDerefEvent {
 struct DefaultBool {
   bool val;
   DefaultBool() : val(false) {}
-  operator bool() const { return val; }
+  LLVM_EXPLICIT operator bool() const { return val; }
   DefaultBool &operator=(bool b) { val = b; return *this; }
 };
 
index b219495d5f06e8c4c7950031cfc772e615d25220..230ce1ea5cf17b9f474a663c198713ce5694ec31 100644 (file)
@@ -231,7 +231,7 @@ public:
 
     bool HandleBinding(StoreManager& SMgr, Store store, const MemRegion* R,
                        SVal val);
-    operator bool() { return First && Binding; }
+    LLVM_EXPLICIT operator bool() { return First && Binding; }
     const MemRegion *getRegion() { return Binding; }
   };
 
index 790538fcd06f4d3920a2a1e9567f218f0dc39ad1..cd974f0d02213562c105de746ca2ed154c9076d2 100644 (file)
@@ -1329,7 +1329,7 @@ void ASTDumper::dumpStmt(const Stmt *S) {
     return;
   }
 
-  setMoreChildren(S->children());
+  setMoreChildren(!S->children().empty());
   ConstStmtVisitor<ASTDumper>::Visit(S);
   setMoreChildren(false);
   for (Stmt::const_child_range CI = S->children(); CI; ++CI) {
index 740b4ff7210f7747f9953ed40f5edd6777b01639..204b9d001c28ceaa3f576086fae36d4200ce2ba0 100644 (file)
@@ -2878,7 +2878,7 @@ Decl *ASTNodeImporter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
 
       if (Importer.IsStructurallyEquivalent(D->getType(), 
                                             FoundField->getType(),
-                                            Name)) {
+                                            !Name.isEmpty())) {
         Importer.Imported(D, FoundField);
         return FoundField;
       }
index 3e4c2cbdb23cc65c32ab69b75a3c335f214dd523..b8f478728f0b18620c2bad8b4e1df657c66f8272 100644 (file)
@@ -2319,7 +2319,7 @@ bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
     const FunctionDecl *Prev = this;
     bool FoundBody = false;
     while ((Prev = Prev->getPreviousDecl())) {
-      FoundBody |= Prev->Body;
+      FoundBody |= Prev->Body.isValid();
 
       if (Prev->Body) {
         // If it's not the case that both 'inline' and 'extern' are
@@ -2347,7 +2347,7 @@ bool FunctionDecl::doesDeclarationForceExternallyVisibleDefinition() const {
   const FunctionDecl *Prev = this;
   bool FoundBody = false;
   while ((Prev = Prev->getPreviousDecl())) {
-    FoundBody |= Prev->Body;
+    FoundBody |= Prev->Body.isValid();
     if (RedeclForcesDefC99(Prev))
       return false;
   }
index 15cf5ac4ab0050cb8c1cf5b9293282fe66e00796..f587dfa93e972bbb0a9af432140fd1c89ed964f0 100644 (file)
@@ -423,7 +423,7 @@ DeclRefExpr *DeclRefExpr::Create(ASTContext &Context,
     FoundD = 0;
 
   std::size_t Size = sizeof(DeclRefExpr);
-  if (QualifierLoc != 0)
+  if (QualifierLoc)
     Size += sizeof(NestedNameSpecifierLoc);
   if (FoundD)
     Size += sizeof(NamedDecl *);
index 2a3efb225bd647c0ed28352da372510c098cb4f0..3741bf12d51947dd165d792238aa74477da6501c 100644 (file)
@@ -1809,7 +1809,7 @@ struct CompleteObject {
     assert(Value && "missing value for complete object");
   }
 
-  operator bool() const { return Value; }
+  LLVM_EXPLICIT operator bool() const { return Value; }
 };
 
 /// Find the designated sub-object of an rvalue.
index 096c7a080bf69577efb643203e2b238ccd736130..6eb84ce92c86ad42866f5ee1093982c352bd4f7c 100644 (file)
@@ -155,7 +155,7 @@ public:
       return !(*this == rhs);
     }
 
-    operator bool() const {
+    LLVM_EXPLICIT operator bool() const {
       return *this != const_iterator();
     }
 
index 6caf1689a9daeab9e33d6cc1d95feab94c95694b..5a7c305c6462872402399ccab9a72152148852b6 100644 (file)
@@ -2422,7 +2422,7 @@ public:
       return ConstantEmission(C, false);
     }
 
-    operator bool() const { return ValueAndIsReference.getOpaqueValue() != 0; }
+    LLVM_EXPLICIT operator bool() const { return ValueAndIsReference.getOpaqueValue() != 0; }
 
     bool isReference() const { return ValueAndIsReference.getInt(); }
     LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const {
index dcf1f0c70c54d7abb861f909b101317c5f5c1f4d..478462c3c20db036e596e19531c8c65d8fd4f83c 100644 (file)
@@ -82,7 +82,7 @@ const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
   if (FileSize <= sizeof(HMapHeader)) return 0;
 
   OwningPtr<const llvm::MemoryBuffer> FileBuffer(FM.getBufferForFile(FE));
-  if (FileBuffer == 0) return 0;  // Unreadable file?
+  if (!FileBuffer) return 0;  // Unreadable file?
   const char *FileStart = FileBuffer->getBufferStart();
 
   // We know the file is at least as big as the header, check it now.
index 50a0cb55f7366bece02bea83eb14975a230c3f3d..ba3291aa398dad2123a0f9ecad20994c66521029 100644 (file)
@@ -241,7 +241,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc,
                                                 bool FoundElse,
                                                 SourceLocation ElseLoc) {
   ++NumSkipped;
-  assert(CurTokenLexer == 0 && CurPPLexer && "Lexing a macro, not a file?");
+  assert(!CurTokenLexer && CurPPLexer && "Lexing a macro, not a file?");
 
   CurPPLexer->pushConditionalLevel(IfTokenLoc, /*isSkipping*/false,
                                  FoundNonSkipPortion, FoundElse);
index be4defe78648b6d3103fc7097bb75d20794f9119..a22d67a6edff429f986e6f9a8188d6386b9cfe6e 100644 (file)
@@ -70,7 +70,7 @@ PreprocessorLexer *Preprocessor::getCurrentFileLexer() const {
 /// start lexing tokens from it instead of the current buffer.
 void Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir,
                                    SourceLocation Loc) {
-  assert(CurTokenLexer == 0 && "Cannot #include a file inside a macro!");
+  assert(!CurTokenLexer && "Cannot #include a file inside a macro!");
   ++NumEnteredSourceFiles;
 
   if (MaxIncludeStackDepth < IncludeMacroStack.size())
index 6a87b78879e860933a3a62519e9ff8427678b6cd..8ad028155ab888ce28132c4d33386508db52284e 100644 (file)
@@ -2524,7 +2524,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
       // erroneous: We already checked about that it has no type specifier, and
       // C++ doesn't have implicit int.  Diagnose it as a typo w.r.t. to the
       // typename.
-      if (TypeRep == 0) {
+      if (!TypeRep) {
         ConsumeToken();   // Eat the scope spec so the identifier is current.
         ParsedAttributesWithRange Attrs(AttrFactory);
         if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) {
index c1c6595d162258f4fe2b56000c7e550e66750ecd..540e8b27fd0caec833ba2fa8d381378e3b14ebdc 100644 (file)
@@ -463,7 +463,7 @@ public:
     }
   }
 
-  bool ok() { return FileStream; }
+  bool ok() { return FileStream.isValid(); }
   raw_ostream &getStream() { return *FileStream; }
 
 private:
index e5e43897ee5f4b918bb93d7ba8a3ce95329d1a1a..437a9da4221fb2c430827be07ed532b31b35a125 100644 (file)
@@ -9307,7 +9307,7 @@ void Sema::DefineImplicitMoveAssignment(SourceLocation CurrentLocation,
   ParmVarDecl *Other = MoveAssignOperator->getParamDecl(0);
   QualType OtherRefType = Other->getType()->
       getAs<RValueReferenceType>()->getPointeeType();
-  assert(OtherRefType.getQualifiers() == 0 &&
+  assert(!OtherRefType.getQualifiers() &&
          "Bad argument type of defaulted move assignment");
 
   // Our location for everything implicitly-generated.
index 07610585c5101374ed6150186bb79db0d6312448..3265ab02dccd819b27627f7db39ccfc7a4021301 100644 (file)
@@ -2945,7 +2945,7 @@ Decl *Sema::ActOnMethodDeclaration(
     QualType ArgType;
     TypeSourceInfo *DI;
 
-    if (ArgInfo[i].Type == 0) {
+    if (!ArgInfo[i].Type) {
       ArgType = Context.getObjCIdType();
       DI = 0;
     } else {
index 2595f2d099c3cde8d7f6c36785ea30aaabc4a6c9..fa2bfd260b9c6cafd3a5a4cde39ef3a4eacb73c7 100644 (file)
@@ -4468,7 +4468,7 @@ Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
 ExprResult
 Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty,
                            SourceLocation RParenLoc, Expr *InitExpr) {
-  assert((Ty != 0) && "ActOnCompoundLiteral(): missing type");
+  assert(Ty && "ActOnCompoundLiteral(): missing type");
   // FIXME: put back this assert when initializers are worked out.
   //assert((InitExpr != 0) && "ActOnCompoundLiteral(): missing expression");
 
index 59a972a4fdfd479a72708be253d5236962f1b7e9..ea0c9e6526833d581d77ad554656aa722a77e30c 100644 (file)
@@ -250,11 +250,12 @@ namespace lifetime {
 }
 
 namespace const_modify {
-  constexpr int modify(int &n) { return n = 1; } // expected-note {{modification of object of const-qualified type 'const int'}}
+  constexpr int modify(int &n) { return n = 1; } // expected-note {{modification of object of const-qualified type 'const int'}}
   constexpr int test1() { int k = 0; return modify(k); }
-  constexpr int test2() { const int k = 0; return modify(const_cast<int&>(k)); } // expected-note {{in call}}
+  constexpr int test2() { const int k = 0; return modify(const_cast<int&>(k)); } // expected-note {{in call}}
   static_assert(test1() == 1, "");
   static_assert(test2() == 1, ""); // expected-error {{constant expression}} expected-note {{in call}}
+  constexpr int i = test2(); // expected-error {{constant expression}} expected-note {{in call}}
 }
 
 namespace null {
index c453b056d257091799ea8858bbd09b9bd08c60f1..defde91b26d816ca9ee659c1ecc275816ae64748 100644 (file)
@@ -453,7 +453,7 @@ TEST(ParseFixedCompilationDatabase, ReturnsArgumentsAfterDoubleDash) {
   const char *Argv[] = { "1", "2", "--\0no-constant-folding", "3", "4" };
   OwningPtr<FixedCompilationDatabase> Database(
       FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
-  ASSERT_TRUE(Database);
+  ASSERT_TRUE(Database.isValid());
   std::vector<CompileCommand> Result =
     Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
@@ -472,7 +472,7 @@ TEST(ParseFixedCompilationDatabase, ReturnsEmptyCommandLine) {
   const char *Argv[] = { "1", "2", "--\0no-constant-folding" };
   OwningPtr<FixedCompilationDatabase> Database(
       FixedCompilationDatabase::loadFromCommandLine(Argc, Argv));
-  ASSERT_TRUE(Database);
+  ASSERT_TRUE(Database.isValid());
   std::vector<CompileCommand> Result =
     Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());