Skip to content

Commit

Permalink
Use cppcheck on header files
Browse files Browse the repository at this point in the history
  • Loading branch information
asherikov committed Jul 21, 2024
1 parent 4a9ce2e commit 6e1501b
Show file tree
Hide file tree
Showing 24 changed files with 70 additions and 34 deletions.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ cppcheck:
# false positive: constStatement, unsignedLessThanZero
cppcheck \
./ \
--inline-suppr \
--relative-paths \
--quiet --verbose --force \
--template='[{file}:{line}] {severity} {id} {message}' \
Expand All @@ -240,6 +241,36 @@ cppcheck:
--suppress=duplInheritedMember \
-i build \
-i tests/api_v2/regression_test_230.cpp \
{} \
3>&1 1>&2 2>&3 | tee cppcheck.err
test 0 -eq `cat cppcheck.err | wc -l && rm cppcheck.err`
# check headers
find ./ -type f -iname '*.hpp' -or -iname "*.h" \
| grep -v "better_enum.h" \
| grep -v ".*build/.*" \
| xargs --max-procs=1 --no-run-if-empty -I {} \
cppcheck \
--inline-suppr \
--relative-paths \
--quiet --verbose --force \
--template='[{file}:{line}] {severity} {id} {message}' \
--language=c++ --std=c++11 \
--enable=warning \
--enable=style \
--enable=performance \
--enable=portability \
--suppress=uninitMemberVar \
--suppress=syntaxError \
--suppress=useInitializationList \
--suppress=functionStatic \
--suppress=unknownMacro \
--suppress=constStatement \
--suppress=unsignedLessThanZero \
--suppress=duplInheritedMember \
--suppress=unreadVariable \
--suppress=unusedStructMember \
-i tests/api_v2/regression_test_230.cpp \
{} \
3>&1 1>&2 2>&3 | tee cppcheck.err
test 0 -eq `cat cppcheck.err | wc -l && rm cppcheck.err`

Expand Down
4 changes: 2 additions & 2 deletions extra_visitors/namevalue/ariles2/visitors/namevalue/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ namespace ariles2
class ARILES2_VISIBILITY_ATTRIBUTE NameValuePairHandler<NameValuePair>
{
public:
static inline std::string &name(NameValuePair &pair)
static inline std::string &name(NameValuePair &pair) // cppcheck-suppress constParameter
{
return (pair.first);
}

static inline double &value(NameValuePair &pair)
static inline double &value(NameValuePair &pair) // cppcheck-suppress constParameter
{
return (pair.second);
}
Expand Down
4 changes: 2 additions & 2 deletions extra_visitors/pugixml/src/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace ariles2

const pugi::xml_parse_result result = impl_->document_.load_file(file_name.c_str(), pugi::parse_minimal);
CPPUT_ASSERT(result, std::string("Parsing of '") + file_name + "' failed: " + result.description());
impl_->node_stack_.push_back(impl_->document_); // NOLINT
impl_->node_stack_.emplace_back(impl_->document_);
}


Expand All @@ -59,7 +59,7 @@ namespace ariles2

const pugi::xml_parse_result result = impl_->document_.load(input_stream, pugi::parse_minimal);
CPPUT_ASSERT(result, std::string("Parsing failed: ") + result.description());
impl_->node_stack_.push_back(impl_->document_); // NOLINT
impl_->node_stack_.emplace_back(impl_->document_);
}


Expand Down
4 changes: 2 additions & 2 deletions extra_visitors/pugixml/src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ namespace ariles2
{
ariles2::write::Visitor::openFile(config_ofs_, file_name);
output_stream_ = &config_ofs_;
node_stack_.push_back(document_); // NOLINT
node_stack_.emplace_back(document_);
}


explicit Writer(std::ostream &output_stream)
{
output_stream_ = &output_stream;
node_stack_.push_back(document_); // NOLINT
node_stack_.emplace_back(document_);
}


Expand Down
1 change: 1 addition & 0 deletions extra_visitors/ros2param/ariles2/visitors/ros2param.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace ariles2

public:
template <class... t_Initializers>
// cppcheck-suppress noExplicitConstructor
Declarator(t_Initializers &&...initializers)
: AggregateBase(std::tuple<>(), std::forward_as_tuple(std::forward<t_Initializers>(initializers)...))
{
Expand Down
4 changes: 2 additions & 2 deletions include/ariles2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ namespace ariles2
{
}

CustomPointerBase(const t_Pointer &value)
explicit CustomPointerBase(const t_Pointer &value)
{
value_ = value;
}

CustomPointerBase(const typename Handler::Value &value)
explicit CustomPointerBase(const typename Handler::Value &value)
{
Handler::allocate(value_);
*value_ = value;
Expand Down
16 changes: 10 additions & 6 deletions include/ariles2/visitors/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ namespace ariles2
typename t_Visitor::Parameters parameters_;

public:
ParametersWrapper(const bool override_parameters = true) : parameters_(override_parameters)
explicit ParametersWrapper(const bool override_parameters = true) : parameters_(override_parameters)
{
}

ParametersWrapper(const typename t_Visitor::Parameters &parameters) : parameters_(parameters)
explicit ParametersWrapper(const typename t_Visitor::Parameters &parameters) : parameters_(parameters)
{
}

Expand Down Expand Up @@ -61,7 +61,7 @@ namespace ariles2
class ARILES2_VISIBILITY_ATTRIBUTE Parameters<>
{
public:
Parameters(const bool){};
explicit Parameters(const bool){};
Parameters(){};

void get(){};
Expand All @@ -72,25 +72,28 @@ namespace ariles2
public Parameters<t_Visitors...>
{
public:
Parameters(const bool override_parameters = true)
explicit Parameters(const bool override_parameters = true)
: ParametersWrapper<t_Visitor>(override_parameters), Parameters<t_Visitors...>(override_parameters)
{
}

template <class... t_Parameters>
// cppcheck-suppress noExplicitConstructor
Parameters(const typename t_Visitor::Parameters &parameters, t_Parameters &&...other_parameters)
: ParametersWrapper<t_Visitor>(parameters)
, Parameters<t_Visitors...>(std::forward<t_Parameters>(other_parameters)...)
{
}

template <class t_Parameters>
// cppcheck-suppress noExplicitConstructor
Parameters(const t_Parameters &parameters, const bool override_parameters = true)
: ParametersWrapper<t_Visitor>(override_parameters)
, Parameters<t_Visitors...>(parameters, override_parameters)
{
}

// cppcheck-suppress noExplicitConstructor
Parameters(const typename t_Visitor::Parameters &parameters, const bool override_parameters = true)
: ParametersWrapper<t_Visitor>(parameters), Parameters<t_Visitors...>(override_parameters)
{
Expand All @@ -110,7 +113,8 @@ namespace ariles2

public:
template <class... t_Args>
BaseVisitorWrapper(const std::tuple<t_Args...> &args_tuple) : visitor_(std::get<t_Args>(args_tuple)...)
explicit BaseVisitorWrapper(const std::tuple<t_Args...> &args_tuple)
: visitor_(std::get<t_Args>(args_tuple)...)
{
}

Expand Down Expand Up @@ -191,7 +195,7 @@ namespace ariles2

public:
template <class... t_Args>
Visitor(t_Args &&...args) : BaseVisitor<t_Visitors...>(std::forward<t_Args>(args)...)
explicit Visitor(t_Args &&...args) : BaseVisitor<t_Visitors...>(std::forward<t_Args>(args)...)
{
}

Expand Down
2 changes: 1 addition & 1 deletion include/ariles2/visitors/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ariles2
bool override_parameters_;

public:
Parameters(const bool override_parameters = true)
explicit Parameters(const bool override_parameters = true)
{
override_parameters_ = override_parameters;
}
Expand Down
2 changes: 1 addition & 1 deletion include/ariles2/visitors/compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ariles2


public:
Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
explicit Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
{
setDefaults();
}
Expand Down
4 changes: 2 additions & 2 deletions include/ariles2/visitors/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace ariles2

public:
template <class... t_Initializers>
Visitor(t_Initializers &&...initializers)
explicit Visitor(t_Initializers &&...initializers)
: AggregateBase(
std::tuple<>(),
std::forward_as_tuple(std::forward<t_Initializers>(initializers)...),
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace ariles2

public:
template <class... t_Initializers>
Visitor(t_Initializers &&...initializers)
explicit Visitor(t_Initializers &&...initializers)
: AggregateBase(std::tuple<>(), std::forward_as_tuple(std::forward<t_Initializers>(initializers)...))
{
CPPUT_TRACE_FUNCTION;
Expand Down
2 changes: 1 addition & 1 deletion include/ariles2/visitors/copyfrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace ariles2
bool deep_copy_;

public:
Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
explicit Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
{
deep_copy_ = true;
}
Expand Down
2 changes: 1 addition & 1 deletion include/ariles2/visitors/copyto.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace ariles2
bool deep_copy_;

public:
Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
explicit Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
{
deep_copy_ = true;
}
Expand Down
2 changes: 1 addition & 1 deletion include/ariles2/visitors/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ariles2
float default_float_value_;

public:
Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
explicit Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
{
#ifdef ARILES2_DEFAULT_DOUBLE_VALUE
default_double_value_ = ARILES2_DEFAULT_DOUBLE_VALUE;
Expand Down
2 changes: 0 additions & 2 deletions include/ariles2/visitors/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ namespace ariles2
return;
default:
CPPUT_THROW("Internal logic error.");
return;
}
}

Expand Down Expand Up @@ -222,7 +221,6 @@ namespace ariles2
virtual bool startIteratedMapElement(std::string & /*entry_name*/)
{
CPPUT_THROW("startIteratedMapElement() is not supported.");
return (false);
}
virtual void endIteratedMapElement()
{
Expand Down
6 changes: 3 additions & 3 deletions include/ariles2/visitors/serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ariles2


public:
Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
explicit Parameters(const bool override_parameters = true) : visitor::Parameters(override_parameters)
{
sloppy_maps_ = false;
sloppy_pairs_ = false;
Expand Down Expand Up @@ -72,13 +72,13 @@ namespace ariles2


public:
Node(const Type type = Type::GENERIC)
explicit Node(const Type type = Type::GENERIC)
{
CPPUT_TRACE_FUNCTION
type_ = type;
}

Node(t_RawNode node, const Type type = Type::GENERIC) : node_(node)
explicit Node(t_RawNode node, const Type type = Type::GENERIC) : node_(node)
{
CPPUT_TRACE_FUNCTION
type_ = type;
Expand Down
2 changes: 1 addition & 1 deletion include/ariles2/visitors/write.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace ariles2


public:
Parameters(const bool override_parameters = true) : serialization::Parameters(override_parameters)
explicit Parameters(const bool override_parameters = true) : serialization::Parameters(override_parameters)
{
compact_arrays_ = false;
}
Expand Down
1 change: 1 addition & 0 deletions qa/scspell.dict
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ codereview
constexpr
copyfrom
copyto
cppcheck
cpput
cstring
ctor
Expand Down
2 changes: 1 addition & 1 deletion tests/api_v2/types/copy/Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace std_msgs
Header_() : seq(0), stamp(), frame_id()
{
}
Header_(const ContainerAllocator &_alloc) : seq(0), stamp(), frame_id(_alloc)
explicit Header_(const ContainerAllocator &_alloc) : seq(0), stamp(), frame_id(_alloc)
{
(void)_alloc;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/api_v2/types/copy/MultiDOFJointTrajectory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace trajectory_msgs
MultiDOFJointTrajectory_() : header(), joint_names(), points()
{
}
MultiDOFJointTrajectory_(const ContainerAllocator &_alloc) : header(_alloc), joint_names(_alloc), points(_alloc)
explicit MultiDOFJointTrajectory_(const ContainerAllocator &_alloc)
: header(_alloc), joint_names(_alloc), points(_alloc)
{
(void)_alloc;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace trajectory_msgs
MultiDOFJointTrajectoryPoint_() : transforms(), velocities(), accelerations(), time_from_start()
{
}
MultiDOFJointTrajectoryPoint_(const ContainerAllocator &_alloc)
explicit MultiDOFJointTrajectoryPoint_(const ContainerAllocator &_alloc)
: transforms(_alloc), velocities(_alloc), accelerations(_alloc), time_from_start()
{
(void)_alloc;
Expand Down
2 changes: 1 addition & 1 deletion tests/api_v2/types/copy/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace geometry_msgs
Quaternion_() : x(0.0), y(0.0), z(0.0), w(0.0)
{
}
Quaternion_(const ContainerAllocator &_alloc) : x(0.0), y(0.0), z(0.0), w(0.0)
explicit Quaternion_(const ContainerAllocator &_alloc) : x(0.0), y(0.0), z(0.0), w(0.0)
{
(void)_alloc;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api_v2/types/copy/Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace geometry_msgs
Transform_() : translation(), rotation()
{
}
Transform_(const ContainerAllocator &_alloc) : translation(_alloc), rotation(_alloc)
explicit Transform_(const ContainerAllocator &_alloc) : translation(_alloc), rotation(_alloc)
{
(void)_alloc;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api_v2/types/copy/Twist.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace geometry_msgs
Twist_() : linear(), angular()
{
}
Twist_(const ContainerAllocator &_alloc) : linear(_alloc), angular(_alloc)
explicit Twist_(const ContainerAllocator &_alloc) : linear(_alloc), angular(_alloc)
{
(void)_alloc;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/api_v2/types/copy/Vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace geometry_msgs
Vector3_() : x(0.0), y(0.0), z(0.0)
{
}
Vector3_(const ContainerAllocator &_alloc) : x(0.0), y(0.0), z(0.0)
explicit Vector3_(const ContainerAllocator &_alloc) : x(0.0), y(0.0), z(0.0)
{
(void)_alloc;
}
Expand Down

0 comments on commit 6e1501b

Please sign in to comment.