Skip to content

Commit 7047ba9

Browse files
author
Simon Pickartz
authored
Merge pull request #53 from spickartz/sp/fix-compiler-warnings
Fix several warnings generated by clang
2 parents 145b439 + 3c503d6 commit 7047ba9

File tree

7 files changed

+37
-25
lines changed

7 files changed

+37
-25
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,16 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
7272
if ("${CMAKE_BUILD_TYPE}" STREQUAL "debug")
7373
ADD_DEFINITIONS(-g3 -O0 -Weverything)
7474

75-
ADD_DEFINITIONS(-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded)
75+
ADD_DEFINITIONS(-Wno-c++98-compat -Wno-shadow -Wno-c++98-compat-pedantic -Wno-padded)
76+
ADD_DEFINITIONS(-Wno-exit-time-destructors -Wno-global-constructors)
7677
endif()
7778

79+
# Options required to reduce the noise of spdlog
80+
ADD_DEFINITIONS(-Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-sign-conversion -Wno-padded -Wno-switch-enum)
81+
ADD_DEFINITIONS(-Wno-old-style-cast -Wno-undef -Wno-documentation-unknown-command)
82+
ADD_DEFINITIONS(-Wno-weak-vtables -Wno-global-constructors -Wno-exit-time-destructors -Wno-newline-eof)
83+
ADD_DEFINITIONS(-Wno-missing-variable-declarations -Wno-double-promotion -Wno-extra-semi)
84+
7885
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
7986
# Using GCC
8087
if ("${CMAKE_BUILD_TYPE}" STREQUAL "release")

include/fast-lib/message/migfra/time_measurement.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Time_measurement :
5151
{
5252
public:
5353
explicit Time_measurement(bool enable_time_measurement = false, std::string format = "", Timer::timepoint_type base_point = Timer::clock::now());
54+
Time_measurement(const Time_measurement &rhs) = default;
55+
Time_measurement & operator=(const Time_measurement &rhs) = default;
5456
~Time_measurement();
5557

5658
void tick(const std::string &timer_name);

include/fast-lib/serializable.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace fast
2424
public:
2525
Serializable() = default;
2626
Serializable(const Serializable&) = default;
27+
Serializable & operator=(const Serializable &rhs) = default;
2728
virtual ~Serializable() = default;
2829

2930
virtual YAML::Node emit() const = 0;

src/message/migfra/pci_id.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ YAML::Node PCI_id::emit() const
6363

6464
void PCI_id::load(const YAML::Node &node)
6565
{
66-
vendor = std::stoul(node["vendor"].as<std::string>(), nullptr, 0);
67-
device = std::stoul(node["device"].as<std::string>(), nullptr, 0);
66+
vendor = static_cast<vendor_t>(std::stoul(node["vendor"].as<std::string>(), nullptr, 0));
67+
device = static_cast<device_t>(std::stoul(node["device"].as<std::string>(), nullptr, 0));
6868
}
6969

7070
std::ostream & operator<<(std::ostream &os, const PCI_id &rhs)

src/message/migfra/task.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,49 +122,49 @@ YAML::Node Task_container::emit() const
122122
Task_container::no_task_exception::no_task_exception(const std::string &str)
123123
: std::runtime_error(str) {}
124124

125-
std::vector<std::shared_ptr<Task>> load_start_task(const YAML::Node &node)
125+
static std::vector<std::shared_ptr<Task>> load_start_task(const YAML::Node &node)
126126
{
127127
std::vector<std::shared_ptr<Start>> tasks;
128128
fast::load(tasks, node["vm-configurations"]);
129129
return std::vector<std::shared_ptr<Task>>(tasks.begin(), tasks.end());
130130
}
131131

132-
std::vector<std::shared_ptr<Task>> load_stop_task(const YAML::Node &node)
132+
static std::vector<std::shared_ptr<Task>> load_stop_task(const YAML::Node &node)
133133
{
134134
std::vector<std::shared_ptr<Stop>> tasks;
135135
fast::load(tasks, node["list"]);
136136
return std::vector<std::shared_ptr<Task>>(tasks.begin(), tasks.end());
137137
}
138138

139-
std::vector<std::shared_ptr<Task>> load_migrate_task(const YAML::Node &node)
139+
static std::vector<std::shared_ptr<Task>> load_migrate_task(const YAML::Node &node)
140140
{
141141
std::shared_ptr<Migrate> migrate_task;
142142
fast::load(migrate_task, node);
143143
return std::vector<std::shared_ptr<Task>>(1, migrate_task);
144144
}
145145

146-
std::vector<std::shared_ptr<Task>> load_repin_task(const YAML::Node &node)
146+
static std::vector<std::shared_ptr<Task>> load_repin_task(const YAML::Node &node)
147147
{
148148
std::shared_ptr<Repin> repin_task;
149149
fast::load(repin_task, node);
150150
return std::vector<std::shared_ptr<Task>>(1, repin_task);
151151
}
152152

153-
std::vector<std::shared_ptr<Task>> load_suspend_task(const YAML::Node &node)
153+
static std::vector<std::shared_ptr<Task>> load_suspend_task(const YAML::Node &node)
154154
{
155155
std::vector<std::shared_ptr<Suspend>> tasks;
156156
fast::load(tasks, node["list"]);
157157
return std::vector<std::shared_ptr<Task>>(tasks.begin(), tasks.end());
158158
}
159159

160-
std::vector<std::shared_ptr<Task>> load_resume_task(const YAML::Node &node)
160+
static std::vector<std::shared_ptr<Task>> load_resume_task(const YAML::Node &node)
161161
{
162162
std::vector<std::shared_ptr<Resume>> tasks;
163163
fast::load(tasks, node["list"]);
164164
return std::vector<std::shared_ptr<Task>>(tasks.begin(), tasks.end());
165165
}
166166

167-
std::vector<std::shared_ptr<Task>> load_quit_task(const YAML::Node &node)
167+
static std::vector<std::shared_ptr<Task>> load_quit_task(const YAML::Node &node)
168168
{
169169
std::shared_ptr<Quit> quit_task;
170170
fast::load(quit_task, node);
@@ -176,7 +176,7 @@ void Task_container::load(const YAML::Node &node)
176176
std::string type;
177177
try {
178178
fast::load(type, node["task"]);
179-
} catch (const std::exception &e) {
179+
} catch (const std::exception /*&e*/) {
180180
throw Task_container::no_task_exception("Cannot find key \"task\" to load Task from YAML.");
181181
}
182182
if (type == "start vm") {

src/message/migfra/time_measurement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void Time_measurement::tock(const std::string &timer_name)
114114
if (enabled) {
115115
try {
116116
timers.at(timer_name).stop();
117-
} catch (const std::out_of_range &e) {
117+
} catch (const std::out_of_range /*&e*/) {
118118
throw std::runtime_error("Timer with name \"" + timer_name + "\" not found. Search for a tock without preceding tick.");
119119
}
120120
}

src/mqtt_communicator.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ FASTLIB_LOG_SET_LEVEL_GLOBAL(comm_log, trace);
2222
namespace fast {
2323

2424
/// Helper function to make error codes human readable.
25-
std::string mosq_err_string(const std::string &str, int code)
25+
static std::string mosq_err_string(const std::string &str, int code)
2626
{
2727
return str + mosqpp::strerror(code);
2828
}
2929

30+
/// Helper function to convert a given topic into a regular expression
31+
static std::regex topic_to_regex(const std::string &topic)
32+
{
33+
// Replace "+" by "[^/]*"
34+
auto regex_topic = std::regex_replace(topic, std::regex(R"((\+))"), R"([^/]*)");
35+
// Replace "#" by "[^/]*(?:/[^/]*)*$"
36+
regex_topic = std::regex_replace(regex_topic, std::regex(R"((#))"), R"([^/]*(?:/[^/]*)*$)");
37+
return std::regex(regex_topic);
38+
}
39+
40+
41+
3042
class MQTT_subscription
3143
{
3244
public:
@@ -249,15 +261,6 @@ void MQTT_communicator::on_disconnect(int rc)
249261
}
250262

251263

252-
std::regex topic_to_regex(const std::string &topic)
253-
{
254-
// Replace "+" by "[^/]*"
255-
auto regex_topic = std::regex_replace(topic, std::regex(R"((\+))"), R"([^/]*)");
256-
// Replace "#" by "[^/]*(?:/[^/]*)*$"
257-
regex_topic = std::regex_replace(regex_topic, std::regex(R"((#))"), R"([^/]*(?:/[^/]*)*$)");
258-
return std::regex(regex_topic);
259-
}
260-
261264
void MQTT_communicator::on_message(const mosquitto_message *msg)
262265
{
263266
FASTLIB_LOG(comm_log, trace) << "Callback: on_message with topic: " << msg->topic;
@@ -294,7 +297,7 @@ void MQTT_communicator::send_message(const std::string &message, const std::stri
294297
// Use default topic if empty string is passed.
295298
auto &real_topic = topic == "" ? default_publish_topic : topic;
296299
// Publish message to topic.
297-
int ret = publish(nullptr, real_topic.c_str(), message.size(), message.c_str(), qos, false);
300+
int ret = publish(nullptr, real_topic.c_str(), static_cast<int>(message.size()), message.c_str(), qos, false);
298301
if (ret != MOSQ_ERR_SUCCESS)
299302
throw std::runtime_error(mosq_err_string("Error sending message: ", ret));
300303
FASTLIB_LOG(comm_log, trace) << "Message sent to topic " << real_topic << ".";
@@ -325,10 +328,9 @@ std::string MQTT_communicator::get_message(const std::string &topic, const std::
325328
auto &subscription = subscriptions.at(topic);
326329
lock.unlock();
327330
return subscription->get_message(duration, actual_topic);
328-
} catch (const std::out_of_range &e) {
331+
} catch (const std::out_of_range /*&e*/) {
329332
throw std::out_of_range("Topic not found in subscriptions.");
330333
}
331-
FASTLIB_LOG(comm_log, trace) << "Message got.";
332334
}
333335

334336

0 commit comments

Comments
 (0)