Questions tagged [clang-static-analyzer]

Use this tag for the Clang Static Analyzer, an open source source code analysis tool which find bugs in C and Objective-C programs. Use this tag also for Xcode Static Analyzer.

The Clang Static Analyzer is an open source (supported by Apple) source code analysis tool which find bugs in C and Objective-C programs.

It can be run either as a standalone tool or within Xcode. The standalone tool is invoked from the command line, and is intended to be run in tandem with a build of a codebase.

The analyzer is 100% open source and is part of the Clang project. Like the rest of Clang, the analyzer is implemented as a C++ library that can be used by other tools and applications.

296 questions
7
votes
3 answers

Analyze Embarcadero RAD Studio project with clang analyzer

I would like to know is it possible to analyze Embarcadero RAD Studio C++ project with Clang Static Analyzer. As far as I understand I need a makefile or something any and ability to build the project with clang. But Embarcadero uses it's own C++…
7
votes
2 answers

How can I specify additional arguments for use with CMAKE_CXX_CLANG_TIDY variable

I'm trying to use make use of clang-tidy integration with cmake and I'd like to pass the -check argument. I've tried adding -DCMAKE_CXX_CLANG_TIDY="/usr/local/opt/llvm38/bin/clang-tidy-3.8;-checks=*" when invoking cmake, but my makefile commands…
Mike Ellery
  • 2,054
  • 3
  • 21
  • 30
6
votes
2 answers

Clang-Tidy slow with dependencies

I am using clang-tidy to lint my code base, but the entire process is very slow. Is there a way to completely ignore header files and not only suppress the warnings? As you can see with this example, a ton of warnings are coming from my project…
6
votes
1 answer

Can a constructor affect other fields of an enclosing object, or is this a static analysis false positive?

Consider this C++ code: struct SomeStruct { SomeStruct() noexcept; }; //SomeStruct::SomeStruct() noexcept {} class SomeClass { const bool b; const SomeStruct s; public: SomeClass() : b(true) {} operator bool() const { return b;…
6
votes
0 answers

Is it possible to get Clang Static Analyzer to understand reference-counting?

The situation: My code uses a reference-counting pointer class (similar in spirit to boost::intrusive_ptr) to manage its dynamic allocations and avoid memory leaks. AFAICT this works fine and does not leak memory; however, when I run Clang Static…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
6
votes
0 answers

Clang-tidy check like LLVMHeaderGuardCheck but for configurable include paths?

Anyone know of any sources for a LLVMHeaderGuardCheck like clang-tidy check that formats the expected include guards based on configurable information like the include path(s) given on the command line? More details... The LLVMHeaderGuardCheck…
Louis Langholtz
  • 2,913
  • 3
  • 17
  • 40
6
votes
2 answers

CRTP copy method warns of potential memory leak

I have an object hierarchy and need to be able to clone objects from the base class. I've followed the typical CRTP pattern, except that I also want to be able to return the child class if copy is called on a child directly. To do that, I've…
Dave
  • 44,275
  • 12
  • 65
  • 105
6
votes
1 answer

how to use clang static analyzer in qt creator

see this manual Using Clang Static Analyzer in Qt Creator manual can someone tell me for to set up this? I don't see this tab in analyzer settings in QtCreator and don't see the plugin in the list which can be used for this... UPDATE: sorry, I see…
amigo421
  • 2,429
  • 4
  • 26
  • 55
5
votes
4 answers

Is it good practice to initialise a variable to nil?

Is it good practice to initialize variable to nil ? I'm asking that because when I run the analyzer on my project I get a warning. NSString *q; if(sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK) { …
objlv
  • 591
  • 1
  • 7
  • 13
5
votes
1 answer

If I use g++ as my compiler, how do I scan a c++ file with the clang static analyzer?

I use g++ to compile my C++ project. When I try to use the clang static analyzer (scan-build) to check my code, I get an error: >> scan-build g++ main.cpp could not find clang line How do I use the scan-build tool with g++?
Stuart Berg
  • 17,026
  • 12
  • 67
  • 99
5
votes
1 answer

Does clang-tidy make scan-build redundant?

I have a project that currently uses both scan-build and clang-tidy (enabled via CMake). If I enable clang-analyzer-* in my set of clang-tidy checks, is the usage of scan-build redundant? For reference, there is a similar question asked here about…
tbre
  • 51
  • 2
5
votes
2 answers

start clang static analyzer with xcodebuild

I'm trying to set up clang static analyzer on a hudson build server and if I follow the advises in this blog post I've got the following errors: cc1obj: error: unrecognized command line option "-fdiagnostics-print-source-range-info" cc1obj: warnings…
Dmytro
  • 2,522
  • 5
  • 27
  • 36
5
votes
2 answers

Configuring static analysis or linters for C++ with Bazel

I'm teaching myself C++ and working on a small project with Bazel. I'd like to make sure I'm writing safe code and following reasonable best practices, but I'm not sure how to go about doing so. I'm aware of several static analysis tools such as…
dimo414
  • 47,227
  • 18
  • 148
  • 244
5
votes
1 answer

Apple changed their Memory Management Rule for Naming Convention

As stated in Cocoa Memory Management Rules from before You take ownership of an object if you create it using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy), or if you send it a…
LaN
  • 228
  • 2
  • 9
5
votes
0 answers

How do I use the clang static analyzer with msbuild on Windows?

The binary windows installer for clang includes scan-build but when you run it with msbuild nothing happens. Even if I do something like: "C:\Program Files\LLVM\bin\scan-build.bat" "C:\Program Files\LLVM\bin\clang.exe" test.cpp I get something…
Jaime
  • 1,182
  • 2
  • 12
  • 29
1 2
3
19 20