浏览代码

Mark operator bool explicit

Regina Pfeifer 7 年之前
父节点
当前提交
a2648dda97
共有 6 个文件被更改,包括 9 次插入12 次删除
  1. 1 7
      Source/cmArchiveWrite.h
  2. 1 1
      Source/cmCTest.h
  3. 1 1
      Source/cmELF.h
  4. 1 1
      Source/cmMachO.h
  5. 1 1
      Source/cmQtAutoGenInitializer.h
  6. 4 1
      Source/cmSystemTools.cxx

+ 1 - 7
Source/cmArchiveWrite.h

@@ -40,9 +40,6 @@ private:
  */
 class cmArchiveWrite
 {
-  typedef void (cmArchiveWrite::*safe_bool)();
-  void safe_bool_true() {}
-
 public:
   /** Compression type.  */
   enum Compress
@@ -73,10 +70,7 @@ public:
            bool recursive = true);
 
   /** Returns true if there has been no error.  */
-  operator safe_bool() const
-  {
-    return this->Okay() ? &cmArchiveWrite::safe_bool_true : nullptr;
-  }
+  explicit operator bool() const { return this->Okay(); }
 
   /** Returns true if there has been an error.  */
   bool operator!() const { return !this->Okay(); }

+ 1 - 1
Source/cmCTest.h

@@ -66,7 +66,7 @@ public:
     const std::string& GetName() const { return this->Name; }
 
     void Enable() { this->Enabled = true; }
-    operator bool() const { return this->Enabled; }
+    explicit operator bool() const { return this->Enabled; }
 
     std::vector<std::string> SubmitFiles;
 

+ 1 - 1
Source/cmELF.h

@@ -32,7 +32,7 @@ public:
   std::string const& GetErrorMessage() const { return this->ErrorMessage; }
 
   /** Boolean conversion.  True if the ELF file is valid.  */
-  operator bool() const { return this->Valid(); }
+  explicit operator bool() const { return this->Valid(); }
 
   /** Enumeration of ELF file types.  */
   enum FileType

+ 1 - 1
Source/cmMachO.h

@@ -30,7 +30,7 @@ public:
   std::string const& GetErrorMessage() const;
 
   /** Boolean conversion.  True if the Mach-O file is valid.  */
-  operator bool() const { return this->Valid(); }
+  explicit operator bool() const { return this->Valid(); }
 
   /** Get Install name from binary **/
   bool GetInstallName(std::string& install_name);

+ 1 - 1
Source/cmQtAutoGenInitializer.h

@@ -54,7 +54,7 @@ public:
     InfoWriter(std::string const& filename);
 
     /// @return True if the file is open
-    operator bool() const { return static_cast<bool>(Ofs_); }
+    explicit operator bool() const { return static_cast<bool>(Ofs_); }
 
     void Write(const char* text) { Ofs_ << text; }
     void Write(const char* key, std::string const& value);

+ 4 - 1
Source/cmSystemTools.cxx

@@ -137,7 +137,10 @@ public:
       CloseHandle(this->handle_);
     }
   }
-  operator bool() const { return this->handle_ != INVALID_HANDLE_VALUE; }
+  explicit operator bool() const
+  {
+    return this->handle_ != INVALID_HANDLE_VALUE;
+  }
   bool operator!() const { return this->handle_ == INVALID_HANDLE_VALUE; }
   operator HANDLE() const { return this->handle_; }