[cfe-dev] c++-analyzer warning question

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Wed Sep 21 04:33:47 PDT 2016


First of all, you shouldn't be calling the "c++-analyzer" executable 
directly. It shouldn't ideally be in your PATH. This script is intended 
to be run by a tool called "scan-build", which essentially does the 
"CXX=c++-analyzer" thing you're doing, just passing a lot of options to 
this script through its own environment variables.

Then scan-build provides html-reports in its output directory (as in 
http://clang-analyzer.llvm.org/ - second screenshot). You see that the 
report is not just a single warning - it consists of multiple diagnostic 
notes or "pieces". Without seeing these pieces, the warning message is 
essentially useless; because the analyzer is designed to find problems 
that occur on specific execution paths.

Once you have the detailed report, the warning should make much more 
sense to you (or maybe it'd disappear for some reason - at least for me 
your code produces no warnings) (or in the worst case at least you'd 
know that it was a false alarm by understanding what kind of mistake the 
analyzer makes).

There are other output modes apart from html, namely text (which dumps 
extra path notes as if there were clang note: diagnostics) and plist 
(which is machine-readable and only used for importing diagnostics into 
IDEs such as Xcode or Qt Creator which provide a graphical interface for 
the clang analyzer).


On 9/21/16 4:05 AM, Dave Flogeras via cfe-dev wrote:
> Hi, I have some code that generates a warning when passed through 
> c++analyzer and I am wondering if someone can help me understand it.
>
> I have put the code for a toy example here 
> https://github.com/dflogeras/analyzer
>
> It uses CMake, I am building on (Gentoo) Linux using clang/LLVM 3.7.1 
> with GCC-4.9.3 headers.  You can build it by doing the following:
> - Install CMake if needed, I'm using 3.5.2
> - Clone the repo
> - Inside the repo make a build dir for out of tree building, ie. 
> path/to/analyzer/build
> - from within build/ run "CXX=c++-analyzer cmake .. 
> -DCMAKE_BUILD_TYPE=Release"
> - once finished, run make
>
> You'll (hopefully) see it generate the warning like
>
> /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/unique_ptr.h:273:4: 
> warning: Potential memory leak
>           return *this;
>
> My question is, is this a proper warning?  Are you not allowed to 
> implicitly upcast a smart_ptr from the return of operator= ?
>
> Thanks for any help, and sorry for any ignorance.
> Dave
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list