0

I've tried to do static code analysis on my project which basically is made up from .hpp files as everthing is "templated" there, but unfortunately I'm getting info from PSV-Studio that header files cannot be processed. That seems bit strange. In modern C++ templates are everywhere and AFAIC they are mostly placed in header files. Am I missing something? Is there a way to set-up PVS-Studio to do analysis on header files?

smallB
  • 16,662
  • 33
  • 107
  • 151
  • Why not `#include` your header in a .cpp file, and analyze that? – Bo Persson Nov 04 '12 at 11:07
  • @BoPersson hi, I've tried it and I'm getting error: Unable to start analysis on this file. Pity. It seems like great overlook on the part of the designers of this product to not analyze header files. – smallB Nov 04 '12 at 12:06
  • "unable to start" indicates that it wants to process the file but can not start that. Possibly because of something that you did wrongly. – Öö Tiib Nov 04 '12 at 12:21
  • 1
    @ÖöTiib It is really difficult to say if what you're saying is correct. Unable to start can mean that it simply is unable to start analysis on this file. It would be good in this day and age to have some meaningful error messages. Maybe I'm doing something wrong. Maybe, but AFAIC if I'm doing something wrong, then it is definitely something wrong with the interface of this program, in the sense that it allows me to do something that I shouldn't and doesn't indicate correct way. – smallB Nov 04 '12 at 12:39
  • @smallB would you like it better if it did say that "preprocessing the file with external preprocessor prior to analysis did fail and preprocessor's log is some link"? No wonder you hate software that hide all diagnostic output of external tools that they use behind such ambiguous messages. Lesson learnt, never write such yourself. – Öö Tiib Nov 04 '12 at 12:57
  • @ÖöTiib I'd prefer if I was told WHY this file cannot be preprocessed, i.e. reason for it. I never said that I hate anything. – smallB Nov 04 '12 at 13:04
  • @smallB the PVS studio likely is not capable to parse the diagnostic log of preprocessor, instead it just translates preprocessor resulted non-zero into "unable to start". – Öö Tiib Nov 04 '12 at 13:12
  • @smallB any chance you happen to know what preprocessors do? It has everything to do with #including header files in cpp files. – Öö Tiib Nov 04 '12 at 13:56
  • @ÖöTiib any chance you're listen to what I say? there is no "include" directive in this particular cpp file. The contents is taken from header file and pasted into cpp file. – smallB Nov 04 '12 at 14:19

1 Answers1

1

PVS-Studio does support analysis of "templated" code, even if it is not instantiated.

However, PVS-Studio needs the file to be preprocessed to analyze it, i.e. all #includes and macros should be expanded before the analysis. To accomplish this, PVS-Studio needs a compilable file, i.e. the file that is passed to the compiler along with the necessary compiler flags (defines, includes, etc.). Having just one header file is insufficient, as PVS-Studio will not have enough information to preprocess it correctly.

The "Unable to start analysis on this file" is most likely a V008 error, meaning that the preprocessor exited with a non-zer code, which means that the file you are trying to analyze is non-compilable. Usually, PVS-Studio will also output the cause of the error (stdErr from the preprocessor process) as the next message. You can read about it in more detail here.

Paul Eremeeff
  • 281
  • 1
  • 4