From 6e1501b3a6e441d143d28aa4ef135e4f09504d97 Mon Sep 17 00:00:00 2001 From: Alexander Sherikov Date: Sun, 21 Jul 2024 18:56:53 +0400 Subject: [PATCH] Use cppcheck on header files --- Makefile | 31 +++++++++++++++++++ .../ariles2/visitors/namevalue/writer.h | 4 +-- extra_visitors/pugixml/src/reader.cpp | 4 +-- extra_visitors/pugixml/src/writer.cpp | 4 +-- .../ros2param/ariles2/visitors/ros2param.h | 1 + include/ariles2/types.h | 4 +-- include/ariles2/visitors/aggregate.h | 16 ++++++---- include/ariles2/visitors/common.h | 2 +- include/ariles2/visitors/compare.h | 2 +- include/ariles2/visitors/config.h | 4 +-- include/ariles2/visitors/copyfrom.h | 2 +- include/ariles2/visitors/copyto.h | 2 +- include/ariles2/visitors/defaults.h | 2 +- include/ariles2/visitors/read.h | 2 -- include/ariles2/visitors/serialization.h | 6 ++-- include/ariles2/visitors/write.h | 2 +- qa/scspell.dict | 1 + tests/api_v2/types/copy/Header.h | 2 +- .../types/copy/MultiDOFJointTrajectory.h | 3 +- .../types/copy/MultiDOFJointTrajectoryPoint.h | 2 +- tests/api_v2/types/copy/Quaternion.h | 2 +- tests/api_v2/types/copy/Transform.h | 2 +- tests/api_v2/types/copy/Twist.h | 2 +- tests/api_v2/types/copy/Vector3.h | 2 +- 24 files changed, 70 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 0e5490cd..31535278 100644 --- a/Makefile +++ b/Makefile @@ -222,6 +222,7 @@ cppcheck: # false positive: constStatement, unsignedLessThanZero cppcheck \ ./ \ + --inline-suppr \ --relative-paths \ --quiet --verbose --force \ --template='[{file}:{line}] {severity} {id} {message}' \ @@ -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` diff --git a/extra_visitors/namevalue/ariles2/visitors/namevalue/writer.h b/extra_visitors/namevalue/ariles2/visitors/namevalue/writer.h index cdf87a12..7a03e210 100644 --- a/extra_visitors/namevalue/ariles2/visitors/namevalue/writer.h +++ b/extra_visitors/namevalue/ariles2/visitors/namevalue/writer.h @@ -33,12 +33,12 @@ namespace ariles2 class ARILES2_VISIBILITY_ATTRIBUTE NameValuePairHandler { 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); } diff --git a/extra_visitors/pugixml/src/reader.cpp b/extra_visitors/pugixml/src/reader.cpp index 3d6e6503..a2872e9c 100644 --- a/extra_visitors/pugixml/src/reader.cpp +++ b/extra_visitors/pugixml/src/reader.cpp @@ -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_); } @@ -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_); } diff --git a/extra_visitors/pugixml/src/writer.cpp b/extra_visitors/pugixml/src/writer.cpp index 346e3b27..936599ef 100644 --- a/extra_visitors/pugixml/src/writer.cpp +++ b/extra_visitors/pugixml/src/writer.cpp @@ -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_); } diff --git a/extra_visitors/ros2param/ariles2/visitors/ros2param.h b/extra_visitors/ros2param/ariles2/visitors/ros2param.h index 436dd9da..ddb386da 100644 --- a/extra_visitors/ros2param/ariles2/visitors/ros2param.h +++ b/extra_visitors/ros2param/ariles2/visitors/ros2param.h @@ -51,6 +51,7 @@ namespace ariles2 public: template + // cppcheck-suppress noExplicitConstructor Declarator(t_Initializers &&...initializers) : AggregateBase(std::tuple<>(), std::forward_as_tuple(std::forward(initializers)...)) { diff --git a/include/ariles2/types.h b/include/ariles2/types.h index 28973cff..1bb188f0 100644 --- a/include/ariles2/types.h +++ b/include/ariles2/types.h @@ -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; diff --git a/include/ariles2/visitors/aggregate.h b/include/ariles2/visitors/aggregate.h index f4477a18..3c74a555 100644 --- a/include/ariles2/visitors/aggregate.h +++ b/include/ariles2/visitors/aggregate.h @@ -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 ¶meters) : parameters_(parameters) + explicit ParametersWrapper(const typename t_Visitor::Parameters ¶meters) : parameters_(parameters) { } @@ -61,7 +61,7 @@ namespace ariles2 class ARILES2_VISIBILITY_ATTRIBUTE Parameters<> { public: - Parameters(const bool){}; + explicit Parameters(const bool){}; Parameters(){}; void get(){}; @@ -72,12 +72,13 @@ namespace ariles2 public Parameters { public: - Parameters(const bool override_parameters = true) + explicit Parameters(const bool override_parameters = true) : ParametersWrapper(override_parameters), Parameters(override_parameters) { } template + // cppcheck-suppress noExplicitConstructor Parameters(const typename t_Visitor::Parameters ¶meters, t_Parameters &&...other_parameters) : ParametersWrapper(parameters) , Parameters(std::forward(other_parameters)...) @@ -85,12 +86,14 @@ namespace ariles2 } template + // cppcheck-suppress noExplicitConstructor Parameters(const t_Parameters ¶meters, const bool override_parameters = true) : ParametersWrapper(override_parameters) , Parameters(parameters, override_parameters) { } + // cppcheck-suppress noExplicitConstructor Parameters(const typename t_Visitor::Parameters ¶meters, const bool override_parameters = true) : ParametersWrapper(parameters), Parameters(override_parameters) { @@ -110,7 +113,8 @@ namespace ariles2 public: template - BaseVisitorWrapper(const std::tuple &args_tuple) : visitor_(std::get(args_tuple)...) + explicit BaseVisitorWrapper(const std::tuple &args_tuple) + : visitor_(std::get(args_tuple)...) { } @@ -191,7 +195,7 @@ namespace ariles2 public: template - Visitor(t_Args &&...args) : BaseVisitor(std::forward(args)...) + explicit Visitor(t_Args &&...args) : BaseVisitor(std::forward(args)...) { } diff --git a/include/ariles2/visitors/common.h b/include/ariles2/visitors/common.h index 8ab80829..ffcc2e60 100644 --- a/include/ariles2/visitors/common.h +++ b/include/ariles2/visitors/common.h @@ -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; } diff --git a/include/ariles2/visitors/compare.h b/include/ariles2/visitors/compare.h index b86dc8c5..fde11ced 100644 --- a/include/ariles2/visitors/compare.h +++ b/include/ariles2/visitors/compare.h @@ -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(); } diff --git a/include/ariles2/visitors/config.h b/include/ariles2/visitors/config.h index e9488ed0..98220274 100644 --- a/include/ariles2/visitors/config.h +++ b/include/ariles2/visitors/config.h @@ -39,7 +39,7 @@ namespace ariles2 public: template - Visitor(t_Initializers &&...initializers) + explicit Visitor(t_Initializers &&...initializers) : AggregateBase( std::tuple<>(), std::forward_as_tuple(std::forward(initializers)...), @@ -67,7 +67,7 @@ namespace ariles2 public: template - Visitor(t_Initializers &&...initializers) + explicit Visitor(t_Initializers &&...initializers) : AggregateBase(std::tuple<>(), std::forward_as_tuple(std::forward(initializers)...)) { CPPUT_TRACE_FUNCTION; diff --git a/include/ariles2/visitors/copyfrom.h b/include/ariles2/visitors/copyfrom.h index c5da65a3..0c5a9366 100644 --- a/include/ariles2/visitors/copyfrom.h +++ b/include/ariles2/visitors/copyfrom.h @@ -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; } diff --git a/include/ariles2/visitors/copyto.h b/include/ariles2/visitors/copyto.h index 8a0e3f81..fff5aa70 100644 --- a/include/ariles2/visitors/copyto.h +++ b/include/ariles2/visitors/copyto.h @@ -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; } diff --git a/include/ariles2/visitors/defaults.h b/include/ariles2/visitors/defaults.h index e88af360..7984f7ab 100644 --- a/include/ariles2/visitors/defaults.h +++ b/include/ariles2/visitors/defaults.h @@ -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; diff --git a/include/ariles2/visitors/read.h b/include/ariles2/visitors/read.h index 7a0009c2..634da691 100644 --- a/include/ariles2/visitors/read.h +++ b/include/ariles2/visitors/read.h @@ -66,7 +66,6 @@ namespace ariles2 return; default: CPPUT_THROW("Internal logic error."); - return; } } @@ -222,7 +221,6 @@ namespace ariles2 virtual bool startIteratedMapElement(std::string & /*entry_name*/) { CPPUT_THROW("startIteratedMapElement() is not supported."); - return (false); } virtual void endIteratedMapElement() { diff --git a/include/ariles2/visitors/serialization.h b/include/ariles2/visitors/serialization.h index 276fbd59..244cc3dc 100644 --- a/include/ariles2/visitors/serialization.h +++ b/include/ariles2/visitors/serialization.h @@ -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; @@ -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; diff --git a/include/ariles2/visitors/write.h b/include/ariles2/visitors/write.h index 5036e0c1..ad0f14be 100644 --- a/include/ariles2/visitors/write.h +++ b/include/ariles2/visitors/write.h @@ -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; } diff --git a/qa/scspell.dict b/qa/scspell.dict index 6d4150b7..6ab7e02f 100644 --- a/qa/scspell.dict +++ b/qa/scspell.dict @@ -17,6 +17,7 @@ codereview constexpr copyfrom copyto +cppcheck cpput cstring ctor diff --git a/tests/api_v2/types/copy/Header.h b/tests/api_v2/types/copy/Header.h index 503d78c3..9407a6c2 100644 --- a/tests/api_v2/types/copy/Header.h +++ b/tests/api_v2/types/copy/Header.h @@ -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; } diff --git a/tests/api_v2/types/copy/MultiDOFJointTrajectory.h b/tests/api_v2/types/copy/MultiDOFJointTrajectory.h index 6b5b3ded..189295d5 100644 --- a/tests/api_v2/types/copy/MultiDOFJointTrajectory.h +++ b/tests/api_v2/types/copy/MultiDOFJointTrajectory.h @@ -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; } diff --git a/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h b/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h index 4e9f563d..b84cd581 100644 --- a/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h +++ b/tests/api_v2/types/copy/MultiDOFJointTrajectoryPoint.h @@ -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; diff --git a/tests/api_v2/types/copy/Quaternion.h b/tests/api_v2/types/copy/Quaternion.h index 590662aa..a53743fc 100644 --- a/tests/api_v2/types/copy/Quaternion.h +++ b/tests/api_v2/types/copy/Quaternion.h @@ -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; } diff --git a/tests/api_v2/types/copy/Transform.h b/tests/api_v2/types/copy/Transform.h index 305c8524..82027f8d 100644 --- a/tests/api_v2/types/copy/Transform.h +++ b/tests/api_v2/types/copy/Transform.h @@ -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; } diff --git a/tests/api_v2/types/copy/Twist.h b/tests/api_v2/types/copy/Twist.h index 5c72cf16..89ceec42 100644 --- a/tests/api_v2/types/copy/Twist.h +++ b/tests/api_v2/types/copy/Twist.h @@ -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; } diff --git a/tests/api_v2/types/copy/Vector3.h b/tests/api_v2/types/copy/Vector3.h index 7c290345..ab6ef977 100644 --- a/tests/api_v2/types/copy/Vector3.h +++ b/tests/api_v2/types/copy/Vector3.h @@ -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; }