Menu

Potential false positive cppcheck performance warning

2025-10-10
2025-10-10
  • Tobias Markus

    Tobias Markus - 2025-10-10

    I'm currently running cppcheck on Google's perfetto source code. See https://github.com/google/perfetto

    Here's part of the source code where it gives me a potential performance info:

    LlvmSymbolizerImpl::LlvmSymbolizerImpl() {
      llvm::symbolize::LLVMSymbolizer::Options opts;
      opts.UseSymbolTable = true;
      opts.Demangle = true;
      opts.PrintFunctions = llvm::symbolize::FunctionNameKind::LinkageName;
      opts.RelativeAddresses = false;
      opts.UntagAddresses = true;
    #if LLVM_VERSION_MAJOR >= 12
      opts.UseDIA = false;
    #endif
    #if LLVM_VERSION_MAJOR >= 11
      opts.PathStyle =
          llvm::DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
    #endif
      symbolizer_ = std::make_unique<llvm::symbolize::LLVMSymbolizer>(opts);
    }
    

    The warning is:

    src/profiling/symbolizer/llvm_symbolizer_wrapper.cc:59:3: performance: Variable 'symbolizer_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList]
      symbolizer_ = std::make_unique<llvm::symbolize::LLVMSymbolizer>(opts);
      ^
    

    However, since the symbolizer_ initialization depends on the variable opts and you can't move all those property assignments happening on opts to the initialization list, I feel like this is a false positive.

     

    Last edit: Tobias Markus 2025-10-10
  • CHR

    CHR - 2025-10-10

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14189

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.