-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix compiler warnings and default to -Wall #53
Fix compiler warnings and default to -Wall #53
Conversation
These look sensible. Changes like this one will help developers more easily build the app on other platforms, too. |
38a6c53
to
0c53342
Compare
I've rebased the original commit and added a second one that makes the codebase compatible with C++11 while staying compatible with C++98. |
@MichaelEischer have you tested this with a four-cam firewire setup to verify that the core functionality is correct? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most changes look good. Good catch finding the operator bugs!
I've requested some clarification on some changes, after which this should be good to go.
@@ -364,7 +364,6 @@ void PluginDVR::slotMovieSave() { | |||
if (output.getNumBytes() > 0) { | |||
//write file: | |||
QString num = QString::number(i); | |||
int n = max(5,num.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why this is no longer required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable was never read, thus no reason to calculate it. Judging from the next two lines it's actually unnecessary.
@@ -48,8 +48,8 @@ PluginLegacyPublishGeometry::PluginLegacyPublishGeometry( | |||
FrameBuffer* fb, | |||
RoboCupSSLServer* ds_udp_server_old, | |||
const RoboCupField& field) : | |||
_ds_udp_server_old(ds_udp_server_old), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why this line had to be moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both clang and g++ complain when fields are not initialized in the order in which they are listed in the header file. In this case the server port was set before calling the super class constructor. As the super class constructor has no means to access this field, there is no change in behavior. Except that compiler stops complaining when -Wall
is used.
@@ -99,8 +107,7 @@ void GLSoccerView::mousePressEvent(QMouseEvent* event) | |||
|
|||
void GLSoccerView::mouseReleaseEvent(QMouseEvent* event) | |||
{ | |||
bool shiftKey = event->modifiers().testFlag(Qt::ShiftModifier); | |||
bool ctrlKey = event->modifiers().testFlag(Qt::ControlModifier); | |||
(void)event; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does removing this result in an unused variable warning? If so, what compiler and version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (void)event
can be removed. I'm not sure whether this was the case when I've made that change.
I've update from Ubuntu 15.10 to Ubuntu 16.04 since I've made the initial version of this commit. My current compiler versions (on Ubuntu 16.04):
- gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)
- Ubuntu clang version 3.7.1-2ubuntu2 (tags/RELEASE_371/final) (based on LLVM 3.7.1)
@@ -138,7 +138,6 @@ RawImage CaptureGenerator::getFrame() | |||
int slice_width = w/n_colors; | |||
rgb color=RGB::Black; | |||
rgb color2; | |||
int gradient=h/256; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an unused var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
vector<VarType *> children=item->getChildren(); | ||
for (unsigned int i=0;i<children.size();i++) { | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="was_read") vwasread=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="enabled") venabled=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="default") vdefault=(VarBool *)children[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these lines removed since the vars are set but not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vauto and vdefault are only read but not used for anything else.
VarBool * vwasread=0; | ||
VarBool * vdefault=0; | ||
|
||
vector<VarType *> children=item->getChildren(); | ||
for (unsigned int i=0;i<children.size();i++) { | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="was_read") vwasread=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="enabled") venabled=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="auto") vauto=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="default") vauto=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="default") vdefault=(VarBool *)children[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is "default" written (line 888), bu t not read (line 831)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vdefault is somehow used to reset vint. Not sure what's exactly happening there.
|
||
vector<VarType *> children=item->getChildren(); | ||
for (unsigned int i=0;i<children.size();i++) { | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="enabled") venabled=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="auto") vauto=(VarBool *)children[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why these lines have been removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those variables are once again never read. I've just noticed that these changes should be accompanied by a cleanup of the var type tree.
@@ -416,7 +416,7 @@ void TeamDetector::findRobotsByModel(::google::protobuf::RepeatedPtrField< ::SSL | |||
(void)image; | |||
const int MaxDetections = _other_markers_max_detections; | |||
Marker cen; // center marker | |||
Marker markers[MaxDetections]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this need to be converted from a stack allocation to a heap allocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang complains otherwise:
variable length array of non-POD element type 'CMPattern::Marker'
POD is short for Plain Old Data. The Marker class has a constructor and thus doesn't count as POD.
@@ -40,14 +40,6 @@ | |||
using namespace std; | |||
namespace CMPattern { | |||
|
|||
class TeamDetectorInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this have to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The update function was out of sync and it's not used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have access to a 2 camera firewire setup. This should nevertheless be enough to test everything important. I should be able to test the changes tomorrow.
It would probably be a good idea to specify what should be tested and to provide a way to test most functions without requiring access to real cameras. I think that most functions could be tested by feeding four recorded camera streams into ssl-vision. That should be enough to test everything except the capture plugins.
The capturev4l changes probably need further cleanups.
@@ -364,7 +364,6 @@ void PluginDVR::slotMovieSave() { | |||
if (output.getNumBytes() > 0) { | |||
//write file: | |||
QString num = QString::number(i); | |||
int n = max(5,num.length()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable was never read, thus no reason to calculate it. Judging from the next two lines it's actually unnecessary.
@@ -48,8 +48,8 @@ PluginLegacyPublishGeometry::PluginLegacyPublishGeometry( | |||
FrameBuffer* fb, | |||
RoboCupSSLServer* ds_udp_server_old, | |||
const RoboCupField& field) : | |||
_ds_udp_server_old(ds_udp_server_old), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both clang and g++ complain when fields are not initialized in the order in which they are listed in the header file. In this case the server port was set before calling the super class constructor. As the super class constructor has no means to access this field, there is no change in behavior. Except that compiler stops complaining when -Wall
is used.
@@ -21,9 +21,9 @@ | |||
#include "multistack_robocup_ssl.h" | |||
|
|||
MultiStackRoboCupSSL::MultiStackRoboCupSSL(RenderOptions * _opts, int cameras) : | |||
MultiVisionStack("RoboCup SSL Multi-Cam",_opts), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same reason as in plugin_legacypublishgeometry.cpp
@@ -99,8 +107,7 @@ void GLSoccerView::mousePressEvent(QMouseEvent* event) | |||
|
|||
void GLSoccerView::mouseReleaseEvent(QMouseEvent* event) | |||
{ | |||
bool shiftKey = event->modifiers().testFlag(Qt::ShiftModifier); | |||
bool ctrlKey = event->modifiers().testFlag(Qt::ControlModifier); | |||
(void)event; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The (void)event
can be removed. I'm not sure whether this was the case when I've made that change.
I've update from Ubuntu 15.10 to Ubuntu 16.04 since I've made the initial version of this commit. My current compiler versions (on Ubuntu 16.04):
- gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)
- Ubuntu clang version 3.7.1-2ubuntu2 (tags/RELEASE_371/final) (based on LLVM 3.7.1)
@@ -138,7 +138,6 @@ RawImage CaptureGenerator::getFrame() | |||
int slice_width = w/n_colors; | |||
rgb color=RGB::Black; | |||
rgb color2; | |||
int gradient=h/256; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
|
||
vector<VarType *> children=item->getChildren(); | ||
for (unsigned int i=0;i<children.size();i++) { | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="enabled") venabled=(VarBool *)children[i]; | ||
if (children[i]->getType()==VARTYPE_ID_BOOL && children[i]->getName()=="auto") vauto=(VarBool *)children[i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those variables are once again never read. I've just noticed that these changes should be accompanied by a cleanup of the var type tree.
@@ -40,14 +40,6 @@ | |||
using namespace std; | |||
namespace CMPattern { | |||
|
|||
class TeamDetectorInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The update function was out of sync and it's not used anywhere else.
@@ -506,6 +506,7 @@ void TeamDetector::findRobotsByModel(::google::protobuf::RepeatedPtrField< ::SSL | |||
robots->RemoveLast(); | |||
} | |||
|
|||
delete markers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be delete[]
. I'm a bit surprised that I didn't notice this given that clang is complaining now.
@@ -416,7 +416,7 @@ void TeamDetector::findRobotsByModel(::google::protobuf::RepeatedPtrField< ::SSL | |||
(void)image; | |||
const int MaxDetections = _other_markers_max_detections; | |||
Marker cen; // center marker | |||
Marker markers[MaxDetections]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang complains otherwise:
variable length array of non-POD element type 'CMPattern::Marker'
POD is short for Plain Old Data. The Marker class has a constructor and thus doesn't count as POD.
@@ -212,9 +212,9 @@ vector3d<num> cross(const vector3d<num> a,const vector3d<num> b) | |||
template <class num> \ | |||
vector3d<num> &vector3d<num>::operator opr (const vector3d<num> p) \ | |||
{ \ | |||
x = x opr p.x; \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was g++ that complained about these assignments. Took me a while to understand what's happening there.
69104d3
to
4eed0c7
Compare
4eed0c7
to
cb906cd
Compare
I've successfully tested the changes with a robot shooting goals in a two camera setup. Currently only a few further cleanups of the capturev4l code remain. |
Michael, thanks for this changeset. |
This fixes all compiler warnings using g++ 5.2.1 (Ubuntu 15.10). Compiling should now also be possible using clang, but that results in a strange linker error for me (probably an incompatibility between g++ 5 and clang related to std::string).
Most changes are unsigned vs signed int, unused variables.
Special ones:
new[]
. This allows compilation using clang+=
would expand tox = x += p.x;
. g++ complains about possibly undefined behavior. Replaced withx += p.x
if (!left < 0)
is always false according to clang. The correct implementation is probably `if (left < 0)