THRIFT-3246 Reduce the number of trivial warnings in Windows C++ CMake builds
Client: cpp
Patch: Ben Craig <bencraig@apache.org>
This closes #553
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index aed3935..847f0ba 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -1748,7 +1748,7 @@
out << indent() << "return this->thriftTExceptionMessageHolder_.c_str();" << endl;
indent_down();
- out << indent() << "} catch (const std::exception& e) {" << endl;
+ out << indent() << "} catch (const std::exception&) {" << endl;
indent_up();
out << indent() << "return \"TException - service has thrown: " << tstruct->get_name() << "\";"
@@ -1801,6 +1801,12 @@
f_header_ << endl << ns_open_ << endl << endl;
+ f_header_ <<
+ "#ifdef _WIN32\n"
+ " #pragma warning( push )\n"
+ " #pragma warning (disable : 4250 ) //inheriting methods via dominance \n"
+ "#endif\n\n";
+
// Service implementation file includes
string f_service_name = get_out_dir() + svcname + ".cpp";
f_service_.open(f_service_name.c_str());
@@ -1851,6 +1857,11 @@
generate_service_async_skeleton(tservice);
}
+ f_header_ <<
+ "#ifdef _WIN32\n"
+ " #pragma warning( pop )\n"
+ "#endif\n\n";
+
// Close the namespace
f_service_ << ns_close_ << endl << endl;
f_service_tcc_ << ns_close_ << endl << endl;
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index 365db8f..427ff41 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -82,6 +82,11 @@
target_link_libraries(UnitTests testgencpp ${Boost_LIBRARIES})
LINK_AGAINST_THRIFT_LIBRARY(UnitTests thrift)
add_test(NAME UnitTests COMMAND UnitTests)
+if ( MSVC )
+ # Disable C4503: decorated name length exceeded, name was truncated
+ # 'insanity' results in very long decorated names
+ set_property( TARGET UnitTests APPEND_STRING PROPERTY COMPILE_FLAGS /wd4503 )
+endif ( MSVC )
add_executable(TSocketInterruptTest TSocketInterruptTest.cpp)
target_link_libraries(TSocketInterruptTest
diff --git a/lib/cpp/test/TNonblockingServerTest.cpp b/lib/cpp/test/TNonblockingServerTest.cpp
index 9488091..8f4ef6e 100644
--- a/lib/cpp/test/TNonblockingServerTest.cpp
+++ b/lib/cpp/test/TNonblockingServerTest.cpp
@@ -38,7 +38,7 @@
// dummy overrides not used in this test
int32_t incrementGeneration() { return 0; }
int32_t getGeneration() { return 0; }
- void getDataWait(std::string&, int32_t) {}
+ void getDataWait(std::string&, const int32_t) {}
void onewayWait() {}
void exceptionWait(const std::string&) {}
void unexpectedExceptionWait(const std::string&) {}
@@ -53,7 +53,7 @@
error = false;
try {
server->serve();
- } catch (const TException& x) {
+ } catch (const TException&) {
error = true;
}
}
@@ -95,7 +95,7 @@
if (userEventBase_) {
try {
server->registerEvents(userEventBase_.get());
- } catch (const TException& x) {
+ } catch (const TException&) {
// retry with next port
continue;
}
diff --git a/lib/cpp/test/TServerIntegrationTest.cpp b/lib/cpp/test/TServerIntegrationTest.cpp
index 42ec5d6..38cbc21 100644
--- a/lib/cpp/test/TServerIntegrationTest.cpp
+++ b/lib/cpp/test/TServerIntegrationTest.cpp
@@ -122,7 +122,7 @@
_return = strings_;
}
- void getDataWait(std::string& _return, int32_t length) {
+ void getDataWait(std::string& _return, const int32_t length) {
THRIFT_UNUSED_VARIABLE(_return);
THRIFT_UNUSED_VARIABLE(length);
}
diff --git a/lib/cpp/test/concurrency/ThreadFactoryTests.h b/lib/cpp/test/concurrency/ThreadFactoryTests.h
index d7431a8..635c8a2 100644
--- a/lib/cpp/test/concurrency/ThreadFactoryTests.h
+++ b/lib/cpp/test/concurrency/ThreadFactoryTests.h
@@ -220,7 +220,7 @@
try {
monitor.wait(100);
- } catch (TimedOutException& e) {
+ } catch (TimedOutException&) {
}
if (state == SynchStartTask::STARTED) {
@@ -257,7 +257,7 @@
Synchronized s(monitor);
try {
monitor.wait(timeout);
- } catch (TimedOutException& e) {
+ } catch (TimedOutException&) {
}
}
}
diff --git a/lib/cpp/test/concurrency/ThreadManagerTests.h b/lib/cpp/test/concurrency/ThreadManagerTests.h
index 904948c..08e8179 100644
--- a/lib/cpp/test/concurrency/ThreadManagerTests.h
+++ b/lib/cpp/test/concurrency/ThreadManagerTests.h
@@ -56,7 +56,7 @@
try {
_sleep.wait(_timeout);
- } catch (TimedOutException& e) {
+ } catch (TimedOutException&) {
;
} catch (...) {
assert(0);
@@ -183,7 +183,7 @@
<< "ms min: " << minTime << "ms max: " << maxTime << "ms average: " << averageTime
<< "ms" << std::endl;
- double expectedTime = ((count + (workerCount - 1)) / workerCount) * timeout;
+ double expectedTime = (double(count + (workerCount - 1)) / workerCount) * timeout;
double error = ((time01 - time00) - expectedTime) / expectedTime;
@@ -290,18 +290,18 @@
try {
threadManager->add(extraTask, 1);
throw TException("Unexpected success adding task in excess of pending task count");
- } catch (TooManyPendingTasksException& e) {
+ } catch (TooManyPendingTasksException&) {
throw TException("Should have timed out adding task in excess of pending task count");
- } catch (TimedOutException& e) {
+ } catch (TimedOutException&) {
// Expected result
}
try {
threadManager->add(extraTask, -1);
throw TException("Unexpected success adding task in excess of pending task count");
- } catch (TimedOutException& e) {
+ } catch (TimedOutException&) {
throw TException("Unexpected timeout adding task in excess of pending task count");
- } catch (TooManyPendingTasksException& e) {
+ } catch (TooManyPendingTasksException&) {
// Expected result
}
@@ -327,12 +327,12 @@
try {
threadManager->add(extraTask, 1);
- } catch (TimedOutException& e) {
+ } catch (TimedOutException&) {
std::cout << "\t\t\t"
<< "add timed out unexpectedly" << std::endl;
throw TException("Unexpected timeout adding task");
- } catch (TooManyPendingTasksException& e) {
+ } catch (TooManyPendingTasksException&) {
std::cout << "\t\t\t"
<< "add encountered too many pending exepctions" << std::endl;
throw TException("Unexpected timeout adding task");
diff --git a/lib/cpp/test/concurrency/TimerManagerTests.h b/lib/cpp/test/concurrency/TimerManagerTests.h
index dda16ed..f4600fc 100644
--- a/lib/cpp/test/concurrency/TimerManagerTests.h
+++ b/lib/cpp/test/concurrency/TimerManagerTests.h
@@ -58,7 +58,7 @@
delta = delta > _timeout ? delta - _timeout : _timeout - delta;
- float error = delta / _timeout;
+ double error = double(delta) / _timeout;
if (error < TEST_TOLERANCE) {
_success = true;
@@ -119,7 +119,7 @@
_monitor.wait(1000);
assert(
0 == "ERROR: This wait should time out. TimerManager dispatcher may have a problem.");
- } catch (TimedOutException& ex) {
+ } catch (TimedOutException&) {
}
task.reset(new TimerManagerTests::Task(_monitor, timeout));
diff --git a/lib/cpp/test/processor/Handlers.h b/lib/cpp/test/processor/Handlers.h
index d894107..c90993a 100644
--- a/lib/cpp/test/processor/Handlers.h
+++ b/lib/cpp/test/processor/Handlers.h
@@ -56,7 +56,7 @@
_return = strings_;
}
- void getDataWait(std::string& _return, int32_t length) {
+ void getDataWait(std::string& _return, const int32_t length) {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_GET_DATA_WAIT, 0, 0);
@@ -139,11 +139,16 @@
boost::shared_ptr<EventLog> log_;
};
+#ifdef _WIN32
+ #pragma warning( push )
+ #pragma warning (disable : 4250 ) //inheriting methods via dominance
+#endif;
+
class ChildHandler : public ParentHandler, virtual public ChildServiceIf {
public:
ChildHandler(const boost::shared_ptr<EventLog>& log) : ParentHandler(log), value_(0) {}
- int32_t setValue(int32_t value) {
+ int32_t setValue(const int32_t value) {
concurrency::Guard g(mutex_);
log_->append(EventLog::ET_CALL_SET_VALUE, 0, 0);
@@ -163,6 +168,10 @@
int32_t value_;
};
+#ifdef _WIN32
+ #pragma warning( pop )
+#endif
+
struct ConnContext {
public:
ConnContext(boost::shared_ptr<protocol::TProtocol> in,
diff --git a/lib/cpp/test/processor/ProcessorTest.cpp b/lib/cpp/test/processor/ProcessorTest.cpp
index 40d926e..5aaa57e 100644
--- a/lib/cpp/test/processor/ProcessorTest.cpp
+++ b/lib/cpp/test/processor/ProcessorTest.cpp
@@ -522,7 +522,7 @@
// can test the timing for the preRead() call.
string requestName = "getDataWait";
string eventName = "ParentService.getDataWait";
- int32_t seqid = time(NULL);
+ int32_t seqid = int32_t(time(NULL));
TBinaryProtocol protocol(socket);
protocol.writeMessageBegin(requestName, T_CALL, seqid);
socket->flush();
@@ -819,7 +819,7 @@
try {
client->recv_unexpectedExceptionWait();
BOOST_FAIL("expected TApplicationError to be thrown");
- } catch (const TApplicationException& e) {
+ } catch (const TApplicationException&) {
}
// Now we should see a handler error event
diff --git a/lib/cpp/test/processor/ServerThread.cpp b/lib/cpp/test/processor/ServerThread.cpp
index 8834269..e9d468f 100644
--- a/lib/cpp/test/processor/ServerThread.cpp
+++ b/lib/cpp/test/processor/ServerThread.cpp
@@ -90,7 +90,7 @@
try {
// Try to serve requests
server_->serve();
- } catch (const TException& x) {
+ } catch (const TException&) {
// TNonblockingServer throws a generic TException if it fails to bind.
// If we get a TException, we'll optimistically assume the bind failed.
++port_;
diff --git a/test/cpp/src/TestServer.cpp b/test/cpp/src/TestServer.cpp
index 526cb0b..7b3c04b 100644
--- a/test/cpp/src/TestServer.cpp
+++ b/test/cpp/src/TestServer.cpp
@@ -304,7 +304,7 @@
hello.i64_thing = (int64_t)arg2;
}
- void testException(const std::string& arg) throw(Xception, apache::thrift::TException) {
+ void testException(const std::string& arg) {
printf("testException(%s)\n", arg.c_str());
if (arg.compare("Xception") == 0) {
Xception e;
@@ -323,7 +323,7 @@
void testMultiException(Xtruct& result,
const std::string& arg0,
- const std::string& arg1) throw(Xception, Xception2) {
+ const std::string& arg1) {
printf("testMultiException(%s, %s)\n", arg0.c_str(), arg1.c_str());