THRIFT-4762: Applied some C++11 refactorings to the runtime library and compiler (#1719)
* make use of C++11 override keyword
* added const specifier to TTransport::getOrigin()
* added more const correctness to the compiler
* make use of auto keyword
* replaced usage of NULL with nullptr
* make use of explicitly-defaulted function definition
* extended changelog
diff --git a/lib/cpp/test/concurrency/Tests.cpp b/lib/cpp/test/concurrency/Tests.cpp
index 019ae67..f2b0111 100644
--- a/lib/cpp/test/concurrency/Tests.cpp
+++ b/lib/cpp/test/concurrency/Tests.cpp
@@ -41,7 +41,7 @@
args[ix - 1] = std::string(argv[ix]);
}
- if (getenv("VALGRIND") != 0) {
+ if (getenv("VALGRIND") != nullptr) {
// lower the scale of every test
WEIGHT = 1;
}
diff --git a/lib/cpp/test/concurrency/ThreadFactoryTests.h b/lib/cpp/test/concurrency/ThreadFactoryTests.h
index ad1613b..febe3f8 100644
--- a/lib/cpp/test/concurrency/ThreadFactoryTests.h
+++ b/lib/cpp/test/concurrency/ThreadFactoryTests.h
@@ -51,7 +51,7 @@
public:
ReapNTask(Monitor& monitor, int& activeCount) : _monitor(monitor), _count(activeCount) {}
- void run() {
+ void run() override {
Synchronized s(_monitor);
if (--_count == 0) {
@@ -122,7 +122,7 @@
SynchStartTask(Monitor& monitor, volatile STATE& state) : _monitor(monitor), _state(state) {}
- void run() {
+ void run() override {
{
Synchronized s(_monitor);
if (_state == SynchStartTask::STARTING) {
@@ -247,14 +247,14 @@
class FloodTask : public Runnable {
public:
FloodTask(const size_t id, Monitor& mon) : _id(id), _mon(mon) {}
- ~FloodTask() {
+ ~FloodTask() override {
if (_id % 10000 == 0) {
Synchronized sync(_mon);
std::cout << "\t\tthread " << _id << " done" << std::endl;
}
}
- void run() {
+ void run() override {
if (_id % 10000 == 0) {
Synchronized sync(_mon);
std::cout << "\t\tthread " << _id << " started" << std::endl;
diff --git a/lib/cpp/test/concurrency/ThreadManagerTests.h b/lib/cpp/test/concurrency/ThreadManagerTests.h
index e9ed756..fee7c7c 100644
--- a/lib/cpp/test/concurrency/ThreadManagerTests.h
+++ b/lib/cpp/test/concurrency/ThreadManagerTests.h
@@ -63,7 +63,7 @@
Task(Monitor& monitor, size_t& count, int64_t timeout)
: _monitor(monitor), _count(count), _timeout(timeout), _startTime(0), _endTime(0), _done(false) {}
- void run() {
+ void run() override {
_startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
@@ -124,7 +124,7 @@
int64_t time00 = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
- for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin();
+ for (auto ix = tasks.begin();
ix != tasks.end();
ix++) {
@@ -151,7 +151,7 @@
int64_t minTime = 9223372036854775807LL;
int64_t maxTime = 0;
- for (std::set<shared_ptr<ThreadManagerTests::Task> >::iterator ix = tasks.begin();
+ for (auto ix = tasks.begin();
ix != tasks.end();
ix++) {
@@ -201,7 +201,7 @@
BlockTask(Monitor& entryMonitor, Monitor& blockMonitor, bool& blocked, Monitor& doneMonitor, size_t& count)
: _entryMonitor(entryMonitor), _entered(false), _blockMonitor(blockMonitor), _blocked(blocked), _doneMonitor(doneMonitor), _count(count) {}
- void run() {
+ void run() override {
{
Synchronized s(_entryMonitor);
_entered = true;
@@ -275,7 +275,7 @@
new ThreadManagerTests::BlockTask(entryMonitor, blockMonitor, blocked[1], doneMonitor, activeCounts[1])));
}
- for (std::vector<shared_ptr<ThreadManagerTests::BlockTask> >::iterator ix = tasks.begin();
+ for (auto ix = tasks.begin();
ix != tasks.end();
ix++) {
threadManager->add(*ix);
diff --git a/lib/cpp/test/concurrency/TimerManagerTests.h b/lib/cpp/test/concurrency/TimerManagerTests.h
index a922826..313572a 100644
--- a/lib/cpp/test/concurrency/TimerManagerTests.h
+++ b/lib/cpp/test/concurrency/TimerManagerTests.h
@@ -44,9 +44,9 @@
_success(false),
_done(false) {}
- ~Task() { std::cerr << this << std::endl; }
+ ~Task() override { std::cerr << this << std::endl; }
- void run() {
+ void run() override {
_endTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
_success = (_endTime - _startTime) >= _timeout;
@@ -215,7 +215,7 @@
// Verify behavior when removing the removed task
try {
timerManager.remove(timer);
- assert(0 == "ERROR: This remove should send a NoSuchTaskException exception.");
+ assert(nullptr == "ERROR: This remove should send a NoSuchTaskException exception.");
} catch (NoSuchTaskException&) {
}
@@ -244,7 +244,7 @@
// Verify behavior when removing the expired task
try {
timerManager.remove(timer);
- assert(0 == "ERROR: This remove should send a NoSuchTaskException exception.");
+ assert(nullptr == "ERROR: This remove should send a NoSuchTaskException exception.");
} catch (NoSuchTaskException&) {
}