clang-power-tools
clang-power-tools copied to clipboard
Ignore thirdparty library errors in clang-tidy
Hi,
we have written cpp code which includes the boost library and while running with clang-tidy,we are getting an error which i am unable to fix since the error is coming from the boost library.
However, we have used some flags in .clang-tidy file like
HeaderFilterRegex: '^(?!.*external).*'
Error: external/boost/boost/assign/list_of.hpp:455:29: error: no matching constructor for initialization of 'boost::assign_detail::generic_list<std::pair<const std::basic_string_view<char16_t, std::char_traits<char16_t> >, std::shared_ptrsabre::base::parsers::ContextSAXHandler > >::Ty' (aka 'std::pair<const std::basic_string_view<char16_t, std::char_traits<char16_t> >, std::shared_ptrsabre::base::parsers::ContextSAXHandler >') [clang-diagnostic-error] this->push_back(Ty(boost::forward<U0>(u0), boost::forward<U1>(u1), boost::forward<Us>(us)...));
Hi @ananta-code,
Thank you for reporting this problem.
I just want to make sure that you know what HeaderFilterRegex does.
HeaderFilterRegex
: Regular expression matching the names of the headers to output diagnostics from. Diagnostics from the main file of each translation unit are always displayed. Can be used together with -line-filter. This option overrides the 'HeaderFilter' option in .clang-tidy file, if any.
In this case, regex needs to include all your headers (except boost) to output diagnostics from.
Maybe you can try checks related to Boost library boost-
to ignore boost headers
Let me know if this answer helped you.
Best regards, Marina
checks related to Boost
Hi @mariru27 , my code is `#include "retailing/mixer/ndc_parser/context_handler/party.h"
#include "base/parsers/ignore_sax_handler.h" #include "retailing/mixer/ndc_parser/context_handler/sender.h"
#include <boost/assign.hpp>
namespace sabre::retailing::mixer::ndc_parser::context_handler { PartySAXHandler::PartySAXHandler(OutputExtractor&& outputExtractor) : base::parsers::ContextSAXHandlerWithMap(boost::assign::list_of<handlers_type::value_type>( "Sender", SenderSAXHandler::create(outputExtractor { return outputExtractor(); }))) {} } // namespace sabre::retailing::mixer::ndc_parser::context_handler `
i have an boost import ..the error i am getting has external and i mentioned this in the regex. even i also tried HeaderFilterRegex: '' and HeaderFilterRegex: '.*' still it is not working
Can you try to add just one header from your project in HeaderFilterRegex to see if the error still appears?
For example: HeaderFilterRegex: 'MyTestHeader.h'
HeaderFilterRegex: 'MyTestHeader.h'
i tried looks like it is not working .clang-tidy:
--- Checks: 'boost-*,bugprone-* --bugprone-narrowing-conversions,cppcoreguidelines-* --cppcoreguidelines-avoid-c-arrays,clang-analyzer-*,modernize-* --modernize-use-trailing-return-type,performance-* --performance-unnecessary-copy-initialization --performance-unnecessary-value-param,readability-* --readability-magic-numbers,hicpp-* --hicpp-no-array-decay,concurrency-*' WarningsAsErrors: '*' HeaderFilterRegex: 'diagnostics.cpp' FormatStyle: file ...
Cpp file: `#include "retailing/mixer/ota_parser/context_handler/diagnostics.h"
#include "retailing/mixer/ota_parser/context_handler/diagnostic.h"
#include <boost/assign.hpp>
namespace sabre::retailing::mixer::ota_parser::context_handler { DiagnosticsSAXHandler::DiagnosticsSAXHandler(OutputExtractor&& outputExtractor) : base_type(boost::assign::list_of<handlers_type::value_type>( "Diagnostic", DiagnosticSAXHandler::create(std::move(outputExtractor)))) {} } // namespace sabre::retailing::mixer::ota_parser::context_handler `
@ananta-code You've given a cpp to the HeaderFilterRegex option, that is for headers.
Is this not the same as #589 ? I would also love to exclude third party libraries from diagnostics. I have no control over their code style / code conventions, as such I should only be bothered about my own stuff. Tried using a HeaderFilterRegex that matches anything not a third party library, yet diagnostic is still run on them and they produce output. Although I have no idea what that regex is actually applied to (e.g. header file names, full path, something else?).
Without the ability to provide excludes in some fashion, it seems pretty cumbersome to use due to all the output for third party libraries that is considered bad style.
Hi @Sil3ntStorm,
Thank you so much for sharing your concerns and providing detailed information about the issue you're facing. I completely understand your frustration with the current situation and the inconvenience caused by the diagnostic output from third-party libraries
We will investigate this problem and work towards finding a solution
Kind regards, Marina
Hi @Sil3ntStorm,
Can you help us by providing a small project with now behavior and how it should work? Verbose log from output will be helpful
Kind regards, Marina
It would appear that my HeaderFilterRegex solution does not work because apparently clang-tidy does not support negative lookaheads in regular expressions.
@mariru27 I will see what I can do over the weekend.