[lld] r181483 - [lld] Add "explicit" to constructors where appropriate.

Rui Ueyama ruiu at google.com
Wed May 8 16:20:54 PDT 2013


Author: ruiu
Date: Wed May  8 18:20:53 2013
New Revision: 181483

URL: http://llvm.org/viewvc/llvm-project?rev=181483&view=rev
Log:
[lld] Add "explicit" to constructors where appropriate.

Summary:
Add the explicit keyword to one-parameter
constructors to prevent unintended type conversions.

CC: llvm-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D765

Modified:
    lld/trunk/include/lld/Core/Atom.h
    lld/trunk/include/lld/Core/Instrumentation.h
    lld/trunk/include/lld/Core/Parallel.h
    lld/trunk/include/lld/Core/Resolver.h
    lld/trunk/include/lld/Core/SharedLibraryFile.h
    lld/trunk/include/lld/Core/SymbolTable.h
    lld/trunk/include/lld/Driver/LinkerInput.h
    lld/trunk/include/lld/Passes/LayoutPass.h
    lld/trunk/include/lld/ReaderWriter/LinkerScript.h
    lld/trunk/include/lld/ReaderWriter/ReaderLinkerScript.h
    lld/trunk/include/lld/ReaderWriter/Simple.h

Modified: lld/trunk/include/lld/Core/Atom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Atom.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Atom.h (original)
+++ lld/trunk/include/lld/Core/Atom.h Wed May  8 18:20:53 2013
@@ -67,7 +67,7 @@ public:
 
 protected:
   /// Atom is an abstract base class.  Only subclasses can access constructor.
-  Atom(Definition def) : _definition(def) {}
+  explicit Atom(Definition def) : _definition(def) {}
 
   /// The memory for Atom objects is always managed by the owning File
   /// object.  Therefore, no one but the owning File object should call

Modified: lld/trunk/include/lld/Core/Instrumentation.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Instrumentation.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Instrumentation.h (original)
+++ lld/trunk/include/lld/Core/Instrumentation.h Wed May  8 18:20:53 2013
@@ -29,7 +29,7 @@ class Domain {
   __itt_domain *_domain;
 
 public:
-  Domain(const char *name) : _domain(__itt_domain_createA(name)) {}
+  explicit Domain(const char *name) : _domain(__itt_domain_createA(name)) {}
 
   operator __itt_domain *() const { return _domain; }
   __itt_domain *operator->() const { return _domain; }

Modified: lld/trunk/include/lld/Core/Parallel.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Parallel.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Parallel.h (original)
+++ lld/trunk/include/lld/Core/Parallel.h Wed May  8 18:20:53 2013
@@ -49,7 +49,7 @@ class Latch {
   mutable std::condition_variable _cond;
 
 public:
-  Latch(uint32_t count = 0) : _count(count) {}
+  explicit Latch(uint32_t count = 0) : _count(count) {}
   ~Latch() { sync(); }
   void inc() { ++_count; }
 
@@ -77,8 +77,8 @@ public:
 ///   in filo order.
 class ThreadPoolExecutor : public Executor {
 public:
-  ThreadPoolExecutor(unsigned threadCount =
-                         std::thread::hardware_concurrency())
+  explicit ThreadPoolExecutor(unsigned threadCount =
+                                  std::thread::hardware_concurrency())
       : _stop(false), _done(threadCount) {
     // Spawn all but one of the threads in another thread as spawning threads
     // can take a while.

Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Wed May  8 18:20:53 2013
@@ -70,21 +70,21 @@ private:
 
     virtual const atom_collection<DefinedAtom> &defined() const {
       return _definedAtoms;
-  }
-  virtual const atom_collection<UndefinedAtom>& undefined() const {
+    }
+    virtual const atom_collection<UndefinedAtom>& undefined() const {
       return _undefinedAtoms;
-  }
-  virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const {
+    }
+    virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const {
       return _sharedLibraryAtoms;
-  }
-  virtual const atom_collection<AbsoluteAtom>& absolute() const {
+    }
+    virtual const atom_collection<AbsoluteAtom>& absolute() const {
       return _absoluteAtoms;
-  }
+    }
 
-  void addAtoms(std::vector<const Atom*>& atoms);
+    void addAtoms(std::vector<const Atom*>& atoms);
 
-  virtual void addAtom(const Atom& atom);
-  virtual DefinedAtomRange definedAtoms();
+    virtual void addAtom(const Atom& atom);
+    virtual DefinedAtomRange definedAtoms();
 
   private:
     friend class Resolver;

Modified: lld/trunk/include/lld/Core/SharedLibraryFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SharedLibraryFile.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SharedLibraryFile.h (original)
+++ lld/trunk/include/lld/Core/SharedLibraryFile.h Wed May  8 18:20:53 2013
@@ -35,7 +35,7 @@ public:
                                            bool dataSymbolOnly) const = 0;
 protected:
   /// only subclasses of SharedLibraryFile can be instantiated
-  SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
+  explicit SharedLibraryFile(StringRef path) : File(path, kindSharedLibrary) {}
 };
 
 } // namespace lld

Modified: lld/trunk/include/lld/Core/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/SymbolTable.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/SymbolTable.h (original)
+++ lld/trunk/include/lld/Core/SymbolTable.h Wed May  8 18:20:53 2013
@@ -37,7 +37,7 @@ class UndefinedAtom;
 /// if an atom has been coalesced away.
 class SymbolTable {
 public:
-  SymbolTable(const TargetInfo &);
+  explicit SymbolTable(const TargetInfo &);
 
   /// @brief add atom to symbol table
   void add(const DefinedAtom &);

Modified: lld/trunk/include/lld/Driver/LinkerInput.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/LinkerInput.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/LinkerInput.h (original)
+++ lld/trunk/include/lld/Driver/LinkerInput.h Wed May  8 18:20:53 2013
@@ -45,9 +45,9 @@ class LinkerInput {
   LinkerInput(const LinkerInput &) LLVM_DELETED_FUNCTION;
 
 public:
-  LinkerInput(StringRef file) : _file(file) {}
+  explicit LinkerInput(StringRef file) : _file(file) {}
 
-  LinkerInput(std::unique_ptr<llvm::MemoryBuffer> buffer)
+  explicit LinkerInput(std::unique_ptr<llvm::MemoryBuffer> buffer)
       : _buffer(std::move(buffer)), _file(_buffer->getBufferIdentifier()) {
   }
 

Modified: lld/trunk/include/lld/Passes/LayoutPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Passes/LayoutPass.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/Passes/LayoutPass.h (original)
+++ lld/trunk/include/lld/Passes/LayoutPass.h Wed May  8 18:20:53 2013
@@ -36,7 +36,7 @@ public:
   // Compare and Sort Atoms by their ordinals
   class CompareAtoms {
   public:
-    CompareAtoms(const LayoutPass &pass) : _layout(pass) {}
+    explicit CompareAtoms(const LayoutPass &pass) : _layout(pass) {}
     bool operator()(const DefinedAtom *left, const DefinedAtom *right);
   private:
     const LayoutPass &_layout;

Modified: lld/trunk/include/lld/ReaderWriter/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/LinkerScript.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/LinkerScript.h (original)
+++ lld/trunk/include/lld/ReaderWriter/LinkerScript.h Wed May  8 18:20:53 2013
@@ -51,7 +51,8 @@ public:
 
 class Lexer {
 public:
-  Lexer(std::unique_ptr<llvm::MemoryBuffer> mb) : _buffer(mb->getBuffer()) {
+  explicit Lexer(std::unique_ptr<llvm::MemoryBuffer> mb)
+      : _buffer(mb->getBuffer()) {
     _sourceManager.AddNewSourceBuffer(mb.release(), llvm::SMLoc());
   }
 
@@ -85,7 +86,7 @@ public:
   virtual ~Command() {}
 
 protected:
-  Command(Kind k) : _kind(k) {}
+  explicit Command(Kind k) : _kind(k) {}
 
 private:
   Kind _kind;
@@ -93,7 +94,7 @@ private:
 
 class OutputFormat : public Command {
 public:
-  OutputFormat(StringRef format)
+  explicit OutputFormat(StringRef format)
       : Command(Kind::OutputFormat), _format(format) {}
 
   static bool classof(const Command *c) {
@@ -115,13 +116,14 @@ struct Path {
   bool _asNeeded;
 
   Path() : _asNeeded(false) {}
-  Path(StringRef path, bool asNeeded = false)
+  explicit Path(StringRef path, bool asNeeded = false)
       : _path(path), _asNeeded(asNeeded) {}
 };
 
 class Group : public Command {
 public:
-  template <class RangeT> Group(RangeT range) : Command(Kind::Group) {
+  template <class RangeT>
+  explicit Group(RangeT range) : Command(Kind::Group) {
     using std::begin;
     using std::end;
     std::copy(begin(range), end(range), std::back_inserter(_paths));
@@ -164,7 +166,7 @@ public:
 
 class Parser {
 public:
-  Parser(Lexer &lex) : _lex(lex) {}
+  explicit Parser(Lexer &lex) : _lex(lex) {}
 
   LinkerScript *parse();
 

Modified: lld/trunk/include/lld/ReaderWriter/ReaderLinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/ReaderLinkerScript.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/ReaderLinkerScript.h (original)
+++ lld/trunk/include/lld/ReaderWriter/ReaderLinkerScript.h Wed May  8 18:20:53 2013
@@ -21,7 +21,7 @@ class TargetInfo;
 /// \brief ReaderLinkerScript is a class for reading linker scripts
 class ReaderLinkerScript : public Reader {
 public:
-  ReaderLinkerScript(const TargetInfo &ti)
+  explicit ReaderLinkerScript(const TargetInfo &ti)
       : Reader(ti) {}
 
   /// \brief Returns a vector of Files that are contained in the archive file

Modified: lld/trunk/include/lld/ReaderWriter/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/Simple.h?rev=181483&r1=181482&r2=181483&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/Simple.h (original)
+++ lld/trunk/include/lld/ReaderWriter/Simple.h Wed May  8 18:20:53 2013
@@ -96,7 +96,7 @@ private:
 
 class SimpleDefinedAtom : public DefinedAtom {
 public:
-  SimpleDefinedAtom(const File &f) : _file(f) {
+  explicit SimpleDefinedAtom(const File &f) : _file(f) {
     static uint32_t lastOrdinal = 0;
     _ordinal = lastOrdinal++;
   }





More information about the llvm-commits mailing list