Skip to content

Commit

Permalink
Add missing, and remove unnecessary, 'explicit' from constructors. (b…
Browse files Browse the repository at this point in the history
…ase/)

The style guide says that constructors which can be called with one
argument should be explicit.

For constructors which cannot be called with exactly one argument,
there is no reason to mark them explicit.

BUG=163357


Review URL: https://chromiumcodereview.appspot.com/11779022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176881 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hans@chromium.org committed Jan 15, 2013
1 parent d443be6 commit f3c697c
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 47 deletions.
4 changes: 2 additions & 2 deletions base/bind_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CopyCounter {
}

// Probing for copies from coercion.
CopyCounter(const DerivedCopyCounter& other)
explicit CopyCounter(const DerivedCopyCounter& other)
: copies_(other.copies_),
assigns_(other.assigns_) {
(*copies_)++;
Expand Down Expand Up @@ -766,7 +766,7 @@ TEST_F(BindTest, ArgumentCopies) {
DerivedCopyCounter dervied(&copies, &assigns);
Callback<void(CopyCounter)> coerce_cb =
Bind(&VoidPolymorphic1<CopyCounter>);
coerce_cb.Run(dervied);
coerce_cb.Run(CopyCounter(dervied));
EXPECT_GE(2, copies);
EXPECT_EQ(0, assigns);
}
Expand Down
2 changes: 1 addition & 1 deletion base/callback_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ TEST_F(CallbackTest, ResetAndReturn) {

class CallbackOwner : public base::RefCounted<CallbackOwner> {
public:
CallbackOwner(bool* deleted) {
explicit CallbackOwner(bool* deleted) {
callback_ = Bind(&CallbackOwner::Unused, this);
deleted_ = deleted;
}
Expand Down
3 changes: 2 additions & 1 deletion base/containers/small_map_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ namespace {
class hash_map_add_item : public hash_map<int, int> {
public:
hash_map_add_item() : hash_map<int, int>() {}
hash_map_add_item(const std::pair<int, int>& item) : hash_map<int, int>() {
explicit hash_map_add_item(const std::pair<int, int>& item)
: hash_map<int, int>() {
insert(item);
}
};
Expand Down
2 changes: 1 addition & 1 deletion base/debug/stack_trace_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class PrintBacktraceOutputHandler : public BacktraceOutputHandler {

class StreamBacktraceOutputHandler : public BacktraceOutputHandler {
public:
StreamBacktraceOutputHandler(std::ostream* os) : os_(os) {
explicit StreamBacktraceOutputHandler(std::ostream* os) : os_(os) {
}

virtual void HandleOutput(const char* output) {
Expand Down
24 changes: 12 additions & 12 deletions base/debug/trace_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,33 +719,33 @@ class TraceID {
unsigned long long data_;
};

explicit TraceID(const void* id, unsigned char* flags)
TraceID(const void* id, unsigned char* flags)
: data_(static_cast<unsigned long long>(
reinterpret_cast<unsigned long>(id))) {
*flags |= TRACE_EVENT_FLAG_MANGLE_ID;
}
explicit TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) {
TraceID(ForceMangle id, unsigned char* flags) : data_(id.data()) {
*flags |= TRACE_EVENT_FLAG_MANGLE_ID;
}
explicit TraceID(unsigned long long id, unsigned char* flags)
TraceID(unsigned long long id, unsigned char* flags)
: data_(id) { (void)flags; }
explicit TraceID(unsigned long id, unsigned char* flags)
TraceID(unsigned long id, unsigned char* flags)
: data_(id) { (void)flags; }
explicit TraceID(unsigned int id, unsigned char* flags)
TraceID(unsigned int id, unsigned char* flags)
: data_(id) { (void)flags; }
explicit TraceID(unsigned short id, unsigned char* flags)
TraceID(unsigned short id, unsigned char* flags)
: data_(id) { (void)flags; }
explicit TraceID(unsigned char id, unsigned char* flags)
TraceID(unsigned char id, unsigned char* flags)
: data_(id) { (void)flags; }
explicit TraceID(long long id, unsigned char* flags)
TraceID(long long id, unsigned char* flags)
: data_(static_cast<unsigned long long>(id)) { (void)flags; }
explicit TraceID(long id, unsigned char* flags)
TraceID(long id, unsigned char* flags)
: data_(static_cast<unsigned long long>(id)) { (void)flags; }
explicit TraceID(int id, unsigned char* flags)
TraceID(int id, unsigned char* flags)
: data_(static_cast<unsigned long long>(id)) { (void)flags; }
explicit TraceID(short id, unsigned char* flags)
TraceID(short id, unsigned char* flags)
: data_(static_cast<unsigned long long>(id)) { (void)flags; }
explicit TraceID(signed char id, unsigned char* flags)
TraceID(signed char id, unsigned char* flags)
: data_(static_cast<unsigned long long>(id)) { (void)flags; }

unsigned long long data() const { return data_; }
Expand Down
2 changes: 1 addition & 1 deletion base/event_recorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BASE_EXPORT EventRecorder {
// Create a new EventRecorder. Events are saved to the file filename.
// If the file already exists, it will be deleted before recording
// starts.
explicit EventRecorder()
EventRecorder()
: is_recording_(false),
is_playing_(false),
#if defined(OS_WIN)
Expand Down
4 changes: 2 additions & 2 deletions base/i18n/char_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace i18n {
class BASE_I18N_EXPORT UTF8CharIterator {
public:
// Requires |str| to live as long as the UTF8CharIterator does.
UTF8CharIterator(const std::string* str);
explicit UTF8CharIterator(const std::string* str);
~UTF8CharIterator();

// Return the starting array index of the current character within the
Expand Down Expand Up @@ -76,7 +76,7 @@ class BASE_I18N_EXPORT UTF8CharIterator {
class BASE_I18N_EXPORT UTF16CharIterator {
public:
// Requires |str| to live as long as the UTF16CharIterator does.
UTF16CharIterator(const string16* str);
explicit UTF16CharIterator(const string16* str);
UTF16CharIterator(const char16* str, size_t str_len);
~UTF16CharIterator();

Expand Down
2 changes: 1 addition & 1 deletion base/memory/ref_counted_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class BASE_EXPORT RefCountedBytes : public RefCountedMemory {
RefCountedBytes();

// Constructs a RefCountedBytes object by _copying_ from |initializer|.
RefCountedBytes(const std::vector<unsigned char>& initializer);
explicit RefCountedBytes(const std::vector<unsigned char>& initializer);

// Constructs a RefCountedBytes object by performing a swap. (To non
// destructively build a RefCountedBytes, use the constructor that takes a
Expand Down
2 changes: 1 addition & 1 deletion base/message_pump_libevent_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ TEST_F(MessagePumpLibeventTest, TestWatchingFromBadThread) {

class BaseWatcher : public MessagePumpLibevent::Watcher {
public:
BaseWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller)
explicit BaseWatcher(MessagePumpLibevent::FileDescriptorWatcher* controller)
: controller_(controller) {
DCHECK(controller_);
}
Expand Down
2 changes: 1 addition & 1 deletion base/metrics/bucket_ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BASE_EXPORT BucketRanges {
public:
typedef std::vector<HistogramBase::Sample> Ranges;

BucketRanges(size_t num_ranges);
explicit BucketRanges(size_t num_ranges);
~BucketRanges();

size_t size() const { return ranges_.size(); }
Expand Down
2 changes: 1 addition & 1 deletion base/metrics/histogram_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BASE_EXPORT HistogramBase {
kHexRangePrintingFlag = 0x8000,
};

HistogramBase(const std::string& name);
explicit HistogramBase(const std::string& name);
virtual ~HistogramBase();

std::string histogram_name() const { return histogram_name_; }
Expand Down
2 changes: 1 addition & 1 deletion base/metrics/histogram_samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace {

class SampleCountPickleIterator : public SampleCountIterator {
public:
SampleCountPickleIterator(PickleIterator* iter);
explicit SampleCountPickleIterator(PickleIterator* iter);

virtual bool Done() const OVERRIDE;
virtual void Next() OVERRIDE;
Expand Down
2 changes: 1 addition & 1 deletion base/metrics/sample_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BASE_EXPORT_PRIVATE SampleMapIterator : public SampleCountIterator {
typedef std::map<HistogramBase::Sample, HistogramBase::Count>
SampleToCountMap;

SampleMapIterator(const SampleToCountMap& sample_counts);
explicit SampleMapIterator(const SampleToCountMap& sample_counts);
virtual ~SampleMapIterator();

// SampleCountIterator implementation:
Expand Down
2 changes: 1 addition & 1 deletion base/metrics/sparse_histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BASE_EXPORT_PRIVATE SparseHistogram : public HistogramBase {

private:
// Clients should always use FactoryGet to create SparseHistogram.
SparseHistogram(const std::string& name);
explicit SparseHistogram(const std::string& name);

friend BASE_EXPORT_PRIVATE HistogramBase* DeserializeHistogramInfo(
PickleIterator* iter);
Expand Down
2 changes: 1 addition & 1 deletion base/synchronization/condition_variable_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ConditionVariableTest : public PlatformTest {
const TimeDelta kSixtyMs;
const TimeDelta kOneHundredMs;

explicit ConditionVariableTest()
ConditionVariableTest()
: kZeroMs(TimeDelta::FromMilliseconds(0)),
kTenMs(TimeDelta::FromMilliseconds(10)),
kThirtyMs(TimeDelta::FromMilliseconds(30)),
Expand Down
4 changes: 2 additions & 2 deletions base/synchronization/lock_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace base {

class BasicLockTestThread : public PlatformThread::Delegate {
public:
BasicLockTestThread(Lock* lock) : lock_(lock), acquired_(0) {}
explicit BasicLockTestThread(Lock* lock) : lock_(lock), acquired_(0) {}

virtual void ThreadMain() OVERRIDE {
for (int i = 0; i < 10; i++) {
Expand Down Expand Up @@ -91,7 +91,7 @@ TEST(LockTest, Basic) {

class TryLockTestThread : public PlatformThread::Delegate {
public:
TryLockTestThread(Lock* lock) : lock_(lock), got_lock_(false) {}
explicit TryLockTestThread(Lock* lock) : lock_(lock), got_lock_(false) {}

virtual void ThreadMain() OVERRIDE {
got_lock_ = lock_->Try();
Expand Down
2 changes: 1 addition & 1 deletion base/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace {
// possible to merge the two.
class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl {
public:
PostTaskAndReplyTaskRunner(TaskRunner* destination);
explicit PostTaskAndReplyTaskRunner(TaskRunner* destination);

private:
virtual bool PostTask(const tracked_objects::Location& from_here,
Expand Down
8 changes: 4 additions & 4 deletions base/test/trace_event_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class Query {

// Find BEGIN events of given |name| which also have associated END events.
static Query MatchBeginName(const std::string& name) {
return (Query(EVENT_NAME) == name) && MatchBeginWithEnd();
return (Query(EVENT_NAME) == Query(name)) && MatchBeginWithEnd();
}

// Match given Process ID and Thread ID.
Expand Down Expand Up @@ -452,16 +452,16 @@ class Query {
};

// Compare with the given member.
Query(TraceEventMember member);
explicit Query(TraceEventMember member);

// Compare with the given member argument value.
Query(TraceEventMember member, const std::string& arg_name);

// Compare with the given string.
Query(const std::string& str);
explicit Query(const std::string& str);

// Compare with the given number.
Query(double num);
explicit Query(double num);

// Construct a boolean Query that returns (left <binary_op> right).
Query(const Query& left, const Query& right, Operator binary_op);
Expand Down
2 changes: 1 addition & 1 deletion base/thread_task_runner_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BASE_EXPORT ThreadTaskRunnerHandle {
// Gets the SingleThreadTaskRunner for the current thread.
static scoped_refptr<SingleThreadTaskRunner> Get();

ThreadTaskRunnerHandle(
explicit ThreadTaskRunnerHandle(
const scoped_refptr<SingleThreadTaskRunner>& task_runner);
~ThreadTaskRunnerHandle();

Expand Down
5 changes: 3 additions & 2 deletions base/threading/non_thread_safe_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class NonThreadSafeClass : public NonThreadSafe {
// Calls NonThreadSafeClass::DoStuff on another thread.
class CallDoStuffOnThread : public SimpleThread {
public:
CallDoStuffOnThread(NonThreadSafeClass* non_thread_safe_class)
explicit CallDoStuffOnThread(NonThreadSafeClass* non_thread_safe_class)
: SimpleThread("call_do_stuff_on_thread"),
non_thread_safe_class_(non_thread_safe_class) {
}
Expand All @@ -65,7 +65,8 @@ class CallDoStuffOnThread : public SimpleThread {
// Deletes NonThreadSafeClass on a different thread.
class DeleteNonThreadSafeClassOnThread : public SimpleThread {
public:
DeleteNonThreadSafeClassOnThread(NonThreadSafeClass* non_thread_safe_class)
explicit DeleteNonThreadSafeClassOnThread(
NonThreadSafeClass* non_thread_safe_class)
: SimpleThread("delete_non_thread_safe_class_on_thread"),
non_thread_safe_class_(non_thread_safe_class) {
}
Expand Down
5 changes: 3 additions & 2 deletions base/threading/thread_checker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ThreadCheckerClass : public ThreadChecker {
// Calls ThreadCheckerClass::DoStuff on another thread.
class CallDoStuffOnThread : public base::SimpleThread {
public:
CallDoStuffOnThread(ThreadCheckerClass* thread_checker_class)
explicit CallDoStuffOnThread(ThreadCheckerClass* thread_checker_class)
: SimpleThread("call_do_stuff_on_thread"),
thread_checker_class_(thread_checker_class) {
}
Expand All @@ -65,7 +65,8 @@ class CallDoStuffOnThread : public base::SimpleThread {
// Deletes ThreadCheckerClass on a different thread.
class DeleteThreadCheckerClassOnThread : public base::SimpleThread {
public:
DeleteThreadCheckerClassOnThread(ThreadCheckerClass* thread_checker_class)
explicit DeleteThreadCheckerClassOnThread(
ThreadCheckerClass* thread_checker_class)
: SimpleThread("delete_thread_checker_class_on_thread"),
thread_checker_class_(thread_checker_class) {
}
Expand Down
2 changes: 1 addition & 1 deletion base/threading/thread_collision_warner.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct BASE_EXPORT DCheckAsserter : public AsserterBase {
class BASE_EXPORT ThreadCollisionWarner {
public:
// The parameter asserter is there only for test purpose
ThreadCollisionWarner(AsserterBase* asserter = new DCheckAsserter())
explicit ThreadCollisionWarner(AsserterBase* asserter = new DCheckAsserter())
: valid_thread_id_(0),
counter_(0),
asserter_(asserter) {}
Expand Down
5 changes: 3 additions & 2 deletions base/threading/worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace {

class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl {
public:
PostTaskAndReplyWorkerPool(bool task_is_slow) : task_is_slow_(task_is_slow) {
explicit PostTaskAndReplyWorkerPool(bool task_is_slow)
: task_is_slow_(task_is_slow) {
}

private:
Expand All @@ -36,7 +37,7 @@ class PostTaskAndReplyWorkerPool : public internal::PostTaskAndReplyImpl {
// Note that this class is RefCountedThreadSafe (inherited from TaskRunner).
class WorkerPoolTaskRunner : public TaskRunner {
public:
WorkerPoolTaskRunner(bool tasks_are_slow);
explicit WorkerPoolTaskRunner(bool tasks_are_slow);

// TaskRunner implementation
virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
Expand Down
2 changes: 1 addition & 1 deletion base/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class BASE_EXPORT Time {
};

// Contains the NULL time. Use Time::Now() to get the current time.
explicit Time() : us_(0) {
Time() : us_(0) {
}

// Returns true if the time object has not been initialized.
Expand Down
2 changes: 1 addition & 1 deletion base/timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace base {
// - abandoned (orphaned) by Timer.
class BaseTimerTaskInternal {
public:
BaseTimerTaskInternal(Timer* timer)
explicit BaseTimerTaskInternal(Timer* timer)
: timer_(timer) {
}

Expand Down
2 changes: 1 addition & 1 deletion base/timer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const int kNumTestingMessageLoops = arraysize(testing_message_loops);

class OneShotTimerTester {
public:
OneShotTimerTester(bool* did_run, unsigned milliseconds = 10)
explicit OneShotTimerTester(bool* did_run, unsigned milliseconds = 10)
: did_run_(did_run),
delay_ms_(milliseconds) {
}
Expand Down
2 changes: 1 addition & 1 deletion base/values.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ValueEquals {
// Pass the value against which all consecutive calls of the () operator will
// compare their argument to. This Value object must not be destroyed while
// the ValueEquals is in use.
ValueEquals(const Value* first) : first_(first) { }
explicit ValueEquals(const Value* first) : first_(first) { }

bool operator ()(const Value* second) const {
return first_->Equals(second);
Expand Down

0 comments on commit f3c697c

Please sign in to comment.