Skip to content

Commit

Permalink
clang-tidy fixes (#1494)
Browse files Browse the repository at this point in the history
* modernize-use-nullptr
* modernize-redundant-void-arg
* modernize-use-override
* readability-redundant-smartptr-get
* readability-container-size-empty
* readability-simplify-boolean-expr
* readability-named-parameter
* llvm-namespace-comment
* fix warnings and remove #pragmas explicitly disabling warnings
* Travis: enable warnings
  • Loading branch information
rhaschke authored Apr 27, 2020
1 parent 4ff6f6a commit 6a3d446
Show file tree
Hide file tree
Showing 94 changed files with 391 additions and 446 deletions.
47 changes: 47 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
Checks: '-*,
llvm-namespace-comment,
modernize-redundant-void-arg,
modernize-use-nullptr,
modernize-use-default,
modernize-use-override,
readability-named-parameter,
readability-redundant-smartptr-get,
readability-redundant-string-cstr,
readability-simplify-boolean-expr,
readability-container-size-empty,
'
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
CheckOptions:
- key: llvm-namespace-comment.ShortNamespaceLines
value: '10'
- key: llvm-namespace-comment.SpacesBeforeComments
value: '2'
- key: readability-braces-around-statements.ShortStatementLines
value: '2'
# type names
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.UnionCase
value: CamelCase
# method names
- key: readability-identifier-naming.MethodCase
value: camelBack
# variable names
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.ClassMemberSuffix
value: '_'
# const static or global variables are UPPER_CASE
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.StaticConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.ClassConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalVariableCase
value: UPPER_CASE
...
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# This config file for Travis CI utilizes https://github.com/ros-planning/moveit_ci/ package.
sudo: required
os: linux
dist: xenial # distro used by Travis, moveit_ci uses the docker image's distro
services:
- docker
language: cpp
cache: ccache
compiler: gcc

notifications:
email: true

env:
global:
- ROS_DISTRO=melodic
- ROS_REPO=ros
- CXXFLAGS="-Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -Wno-strict-aliasing -Wno-sign-compare"
- WARNINGS_OK=true
- ABI_BASE_URL=https://ni.www.techfak.uni-bielefeld.de/abicheck/rviz-${ROS_DISTRO}.tar.gz
matrix:

jobs:
- TEST=catkin_lint
- TEST=abi
- TEST=abi,clang-tidy-fix

before_script:
- git clone -q --depth=1 https://github.com/ros-planning/moveit_ci.git .moveit_ci
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ include_directories(SYSTEM
${urdfdom_headers_INCLUDE_DIRS}
)
#catkin_lint: ignore_once external_directory
include_directories(src ${EXPORT_HEADER_DIR} ${catkin_INCLUDE_DIRS})
include_directories(src ${EXPORT_HEADER_DIR})
include_directories(SYSTEM ${catkin_INCLUDE_DIRS})

#### If gtk ends up being the best way to get the correct window
#### position under X11, this is how to compile it in.
Expand Down
10 changes: 5 additions & 5 deletions src/rviz/add_display_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void getPluginGroups( const QMap<QString, QString> &datatype_plugins,

if ( datatype_plugins.contains( datatype ) )
{
if ( groups->size() == 0 ||
if ( groups->empty() ||
!isSubtopic(groups->back().base_topic.toStdString(),
topic.toStdString()) )
{
Expand Down Expand Up @@ -282,7 +282,7 @@ void AddDisplayDialog::onTopicSelected( SelectionData *data )

void AddDisplayDialog::updateDisplay()
{
SelectionData *data = NULL;
SelectionData *data = nullptr;
if ( tab_widget_->currentIndex() == topic_tab_ )
{
data = &topic_data_;
Expand Down Expand Up @@ -373,7 +373,7 @@ void DisplayTypeTree::onCurrentItemChanged(QTreeWidgetItem *curr,
{
// If display is selected, populate selection data. Otherwise, clear data.
SelectionData sd;
if ( curr->parent() != NULL )
if ( curr->parent() != nullptr )
{
// Leave topic and datatype blank
sd.whats_this = curr->whatsThis( 0 );
Expand Down Expand Up @@ -477,7 +477,7 @@ void TopicDisplayWidget::onCurrentItemChanged( QTreeWidgetItem* curr )
sd.display_name = curr->text( 0 );

QComboBox *combo = qobject_cast<QComboBox*>( tree_->itemWidget( curr, 1 ) );
if ( combo != NULL )
if ( combo != nullptr )
{
QString combo_text = combo->currentText();
if ( combo_text != "raw" )
Expand Down Expand Up @@ -622,4 +622,4 @@ QTreeWidgetItem* TopicDisplayWidget::insertItem( const QString &topic,
return current;
}

} // rviz
} // namespace rviz
22 changes: 11 additions & 11 deletions src/rviz/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Config::Node
Config::Node::Node()
: type_( Empty )
{
data_.map = NULL;
data_.map = nullptr;
}

Config::Node::~Node()
Expand All @@ -80,7 +80,7 @@ void Config::Node::deleteData()
default:
break;
}
data_.map = NULL;
data_.map = nullptr;
}

void Config::Node::setType( Config::Type new_type )
Expand Down Expand Up @@ -201,7 +201,7 @@ Config Config::mapMakeChild( const QString& key )

Config Config::mapGetChild( const QString& key ) const
{
if( node_.get() == NULL || node_->type_ != Map )
if( node_.get() == nullptr || node_->type_ != Map )
{
return invalidConfig();
}
Expand Down Expand Up @@ -292,15 +292,15 @@ bool Config::mapGetString( const QString& key, QString *value_out ) const

void Config::makeValid()
{
if( node_.get() == NULL )
if( node_.get() == nullptr )
{
node_.reset( new Node() );
}
}

bool Config::isValid() const
{
return node_.get() != NULL;
return node_.get() != nullptr;
}

void Config::setValue( const QVariant& value )
Expand Down Expand Up @@ -347,7 +347,7 @@ Config::MapIterator Config::mapIterator() const
// Create a new (invalid) iterator.
Config::MapIterator iter;

if( node_.get() == NULL || node_->type_ != Map )
if( node_.get() == nullptr || node_->type_ != Map )
{
// Force the node to be invalid, since this node does not have a map.
iter.node_.reset();
Expand All @@ -367,7 +367,7 @@ Config::MapIterator::MapIterator()

void Config::MapIterator::advance()
{
if( node_.get() == NULL || node_->type_ != Config::Map )
if( node_.get() == nullptr || node_->type_ != Config::Map )
{
iterator_valid_ = false;
return;
Expand All @@ -385,7 +385,7 @@ void Config::MapIterator::advance()

bool Config::MapIterator::isValid()
{
if( node_.get() == NULL || node_->type_ != Config::Map )
if( node_.get() == nullptr || node_->type_ != Config::Map )
{
iterator_valid_ = false;
return false;
Expand All @@ -402,7 +402,7 @@ bool Config::MapIterator::isValid()

void Config::MapIterator::start()
{
if( node_.get() == NULL || node_->type_ != Config::Map )
if( node_.get() == nullptr || node_->type_ != Config::Map )
{
iterator_valid_ = false;
return;
Expand All @@ -413,7 +413,7 @@ void Config::MapIterator::start()

QString Config::MapIterator::currentKey()
{
if( node_.get() == NULL || node_->type_ != Config::Map || !iterator_valid_ )
if( node_.get() == nullptr || node_->type_ != Config::Map || !iterator_valid_ )
{
iterator_valid_ = false;
return QString();
Expand All @@ -423,7 +423,7 @@ QString Config::MapIterator::currentKey()

Config Config::MapIterator::currentChild()
{
if( node_.get() == NULL || node_->type_ != Config::Map || !iterator_valid_ )
if( node_.get() == nullptr || node_->type_ != Config::Map || !iterator_valid_ )
{
iterator_valid_ = false;
return Config();
Expand Down
17 changes: 3 additions & 14 deletions src/rviz/default_plugin/axes_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,9 @@

#include <boost/bind.hpp>

#ifndef _WIN32
# pragma GCC diagnostic push
# ifdef __clang__
# pragma clang diagnostic ignored "-W#warnings"
# endif
#endif

#include <OgreSceneNode.h>
#include <OgreSceneManager.h>

#ifndef _WIN32
# pragma GCC diagnostic pop
#endif

#include "rviz/display_context.h"
#include "rviz/frame_manager.h"
#include "rviz/ogre_helpers/axes.h"
Expand All @@ -56,11 +45,11 @@ namespace rviz

AxesDisplay::AxesDisplay()
: Display()
, axes_( 0 )
, axes_( nullptr )
{
frame_property_ = new TfFrameProperty( "Reference Frame", TfFrameProperty::FIXED_FRAME_STRING,
"The TF frame these axes will use for their origin.",
this, NULL, true );
this, nullptr, true );

length_property_ = new FloatProperty( "Length", 1.0,
"Length of each axis, in meters.",
Expand All @@ -82,7 +71,7 @@ void AxesDisplay::onInitialize()
{
frame_property_->setFrameManager( context_->getFrameManager() );

axes_ = new Axes( scene_manager_, 0, length_property_->getFloat(), radius_property_->getFloat() );
axes_ = new Axes( scene_manager_, nullptr, length_property_->getFloat(), radius_property_->getFloat() );
axes_->getSceneNode()->setVisible( isEnabled() );
}

Expand Down
13 changes: 1 addition & 12 deletions src/rviz/default_plugin/camera_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@

#include <boost/bind.hpp>

#ifndef _WIN32
# pragma GCC diagnostic push
# ifdef __clang__
# pragma clang diagnostic ignored "-W#warnings"
# endif
#endif

#include <OgreManualObject.h>
#include <OgreMaterialManager.h>
#include <OgreRectangle2D.h>
Expand All @@ -48,10 +41,6 @@
#include <OgreTechnique.h>
#include <OgreCamera.h>

#ifndef _WIN32
# pragma GCC diagnostic pop
#endif

#include <tf2_ros/message_filter.h>

#include "rviz/bit_allocator.h"
Expand Down Expand Up @@ -92,7 +81,7 @@ bool validateFloats(const sensor_msgs::CameraInfo& msg)
CameraDisplay::CameraDisplay()
: ImageDisplayBase()
, texture_()
, render_panel_( 0 )
, render_panel_( nullptr )
, caminfo_ok_( false )
, force_render_( false )
{
Expand Down
7 changes: 2 additions & 5 deletions src/rviz/default_plugin/covariance_visual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void radianScaleToMetricScaleBounded(Ogre::Real & radian_scale, float max_degree
}


}
} // namespace

const float CovarianceVisual::max_degrees = 89.0;

Expand Down Expand Up @@ -292,10 +292,7 @@ void CovarianceVisual::setCovariance( const geometry_msgs::PoseWithCovariance& p
}
}

if(pose.covariance[14] <= 0 && pose.covariance[21] <= 0 && pose.covariance[28] <= 0 )
pose_2d_ = true;
else
pose_2d_ = false;
pose_2d_ = pose.covariance[14] <= 0 && pose.covariance[21] <= 0 && pose.covariance[28] <= 0;

updateOrientationVisibility();

Expand Down
10 changes: 5 additions & 5 deletions src/rviz/default_plugin/depth_cloud_mld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ template<typename T>
sensor_msgs::PointCloud2Ptr cloud_msg = initPointCloud();
cloud_msg->data.resize(height * width * cloud_msg->point_step);

uint32_t* color_img_ptr = 0;
uint32_t* color_img_ptr = nullptr;

if (rgba_color_raw.size())
if (!rgba_color_raw.empty())
color_img_ptr = &rgba_color_raw[0];

////////////////////////////////////////////////
Expand Down Expand Up @@ -258,9 +258,9 @@ template<typename T>
sensor_msgs::PointCloud2Ptr cloud_msg = initPointCloud();
cloud_msg->data.resize(height * width * cloud_msg->point_step * 2);

uint32_t* color_img_ptr = 0;
uint32_t* color_img_ptr = nullptr;

if (rgba_color_raw.size())
if (!rgba_color_raw.empty())
color_img_ptr = &rgba_color_raw[0];

////////////////////////////////////////////////
Expand Down Expand Up @@ -581,4 +581,4 @@ void MultiLayerDepth::finalizingPointCloud(sensor_msgs::PointCloud2Ptr& point_cl
point_cloud->row_step = point_cloud->point_step * point_cloud->width;
}

}
} // namespace rviz
2 changes: 1 addition & 1 deletion src/rviz/default_plugin/effort_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace rviz
M_JointInfo::iterator it = joints_.find( joint );
if ( it == joints_.end() )
{
return NULL;
return nullptr;
}

return it->second;
Expand Down
15 changes: 0 additions & 15 deletions src/rviz/default_plugin/grid_cells_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,11 @@
*/

#include <boost/bind.hpp>

#ifndef _WIN32
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wpedantic"
# ifdef __clang__
# pragma clang diagnostic ignored "-Wdeprecated-register"
# endif
# pragma GCC diagnostic ignored "-Woverloaded-virtual"
# pragma GCC diagnostic ignored "-Wunused-parameter"
#endif

#include <OgreSceneNode.h>
#include <OgreSceneManager.h>
#include <OgreManualObject.h>
#include <OgreBillboardSet.h>

#ifndef _WIN32
# pragma GCC diagnostic pop
#endif

#include "rviz/frame_manager.h"
#include "rviz/ogre_helpers/arrow.h"
#include "rviz/ogre_helpers/point_cloud.h"
Expand Down
Loading

0 comments on commit 6a3d446

Please sign in to comment.