0

I have a simple c++ project with Bazel. I'm running some simple tests using the Google Test framework. Clang-tidy seems to complain about almost every single macro from that framework. Is there a way to get clang to ignore those macros? I tried using //NOLINT but it doesn't seem to do anything.

My clang-tidy config file is this:

Checks:          '-*,clang-analyzer-*,
            modernize-avoid-bind,
            modernize-avoid-c-arrays,
            modernize-concat-nested-namespaces,
            modernize-deprecated-headers,
            modernize-deprecated-ios-base-aliases,  
            modernize-loop-convert,     
            modernize-make-shared,  
            modernize-make-unique,  
            modernize-pass-by-value,    
            modernize-raw-string-literal,   
            modernize-redundant-void-arg,   
            modernize-replace-auto-ptr,     
            modernize-replace-disallow-copy-and-assign-macro,   
            modernize-replace-random-shuffle,   
            modernize-return-braced-init-list,  
            modernize-shrink-to-fit,    
            modernize-unary-static-assert,  
            modernize-use-auto,     
            modernize-use-bool-literals,    
            modernize-use-default-member-init,  
            modernize-use-emplace,  
            modernize-use-equals-default,   
            modernize-use-equals-delete,    
            modernize-use-nodiscard,    
            modernize-use-noexcept,     
            modernize-use-nullptr,  
            modernize-use-override,     
            modernize-use-transparent-functors,     
            modernize-use-uncaught-exceptions,  
            modernize-use-using,    
            performance-*,readability*,cppcoreguidelines-*, llvm-*,
            google-*,
            bugprone-*'
  WarningsAsErrors: ''
  HeaderFilterRegex: ''
  AnalyzeTemporaryDtors: false
  CheckOptions:
        [{key: readability-identifier-naming.ClassCase, value: CamelCase},
        {key: readability-identifier-naming.ClassMemberCase, value: lower_case},
        {key: readability-identifier-naming.PrivateMemberPrefix, value: m_},
        {key: readability-identifier-naming.ClassMethodCase, value: lower_case},
        {key: readability-identifier-naming.StructCase, value: lower_case},
        {key: readability-identifier-naming.VariableCase, value: lower_case},
        {key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE},
         ]

The warning that I get is Initializing non-owner argument of type 'testing::internal::TestFactoryBase *' with a newly created 'gsl::owner<>'clang-tidy(cppcoreguidelines-owning-memory)

1 Answers1

0

//NOLINT needs to be placed where the issue appears in the code, i.e. where you use the macro. This can be cumbersome if you have it many places.

Another option would be to either exclude your test files clang-tidy cmake exclude file from check Or configure 2 clang-tidy runs (one for test without the check and one for prod with the check). Not sure if you can model this in Bazel, as I didn't use it so far

Last option: Open an issue in GitHub https://github.com/google/googletest/issues or fix it yourself in the googletest source code and open a pull request.

Rene Oschmann
  • 676
  • 4
  • 16