Skip to content
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

Merged
merged 3 commits into from
Oct 19, 2016

Conversation

MichaelEischer
Copy link
Contributor

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:

  • Allocate marker array in cmpattern_teamdetector.cpp using new[]. This allows compilation using clang
  • Remove the TeamDetectorInterface from cmpattern_teamdetector.h. The interface is not used and defines an update function that differs from the one that's actually used.
  • Used isnan from cmath in glcamera.h .
  • Fix operators in gvector.h : += would expand to x = x += p.x;. g++ complains about possibly undefined behavior. Replaced with x += p.x
  • In random.cpp : if (!left < 0) is always false according to clang. The correct implementation is probably `if (left < 0)

@ezavesky
Copy link
Contributor

These look sensible. Changes like this one will help developers more easily build the app on other platforms, too.

@MichaelEischer
Copy link
Contributor Author

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.
@joydeep-b: Any chance to merge this any time soon?

@joydeep-b
Copy link
Member

@MichaelEischer have you tested this with a four-cam firewire setup to verify that the core functionality is correct?
I have a few questions regarding specific line changes, shall comment inline.

Copy link
Member

@joydeep-b joydeep-b left a 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());
Copy link
Member

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?

Copy link
Contributor Author

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),
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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];
Copy link
Member

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?

Copy link
Contributor Author

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];
Copy link
Member

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)?

Copy link
Contributor Author

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];
Copy link
Member

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?

Copy link
Contributor Author

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];
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@MichaelEischer MichaelEischer left a 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());
Copy link
Contributor Author

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),
Copy link
Contributor Author

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),
Copy link
Contributor Author

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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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];
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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;
Copy link
Contributor Author

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];
Copy link
Contributor Author

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; \
Copy link
Contributor Author

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.

@MichaelEischer
Copy link
Contributor Author

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.

@joydeep-b
Copy link
Member

Michael, thanks for this changeset.
Looking through the source, it seems that the v4l drivers are sorely in need of cleanup, along with some paring of the associated VarTree. I'll add that as an issue.
For now, this changeset looks good to me.

@joydeep-b joydeep-b closed this Oct 19, 2016
@joydeep-b joydeep-b reopened this Oct 19, 2016
@joydeep-b joydeep-b merged commit 2ab4a28 into RoboCup-SSL:master Oct 19, 2016
@MichaelEischer MichaelEischer deleted the fix-compiler-warnings branch October 29, 2016 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants