Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Coverity static analysis compatible with C++0x standard?

I am using a Wind River Compiler 4 (gcc (C) and g++ (C++)) and it compiles all my projects without any problems. Now I have to use Coverity Static Analysis to check my code. I have configured the specific compilers. For the C-Code (gcc) there are no problems and I can run the analysis, but for the C++-Code (g++) I got a lot of errors:

.../c++config.h", line 214: error #40:
    expected an identifier
inline namespace __gnu_cxx_ldbl128 { }
       ^

.../c++config.h", line 214: error #326:
    inline specifier allowed on function declarations only
inline namespace __gnu_cxx_ldbl128 { }
^

.../c++config.h", line 214: error #65:
    expected a ";"
inline namespace __gnu_cxx_ldbl128 { }
                                   ^
.../include/string.h", line 76: error #312:
    cannot overload functions distinguished by return type alone
extern __const void *memchr (__const void *__s, int __c, size_t __n)
                     ^

.../include/string.h", line 116: error #312:
    cannot overload functions distinguished by return type alone
extern "C++" __const void *memchr (__const void *__s, int __c, size_t __n)
                     ^

It seem to be some C++11 specific features like the inline namespace but the code doesn't use these features. The errors above are produced with a HelloWorld-Code:

#include "stdio.h"
#include "util.h"
#include <string>
#include "string.h"

using namespace std;

int main()
{
    printf("Hello World, C++ version: %d.%d.%d\r\n",__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__);

    return 0;
}

I have tried to set the c++ standard with the g++ option

-std=c++98

but the result doesn't changed.

The Test-Code is in a big build hierarchy but the steps for Coverity are like this:

  1. target and env set (Wind River 4 Linux)
  2. make clean
  3. cov-configure with compiler dir and type
  4. cov-build with the correct "make all" command that works alone
  5. cov-analyze
  6. if (no_error) cov-commit-defects

I have also configured Coverity to replace all "inline namespace" with "namespace" during the cov-build (--ppp-translator replace/inline namespace/namespace). The inline errors disappeared but it produces more of this overload errors and no succecfully build. Also tried to remove the "C++" the same way but didn't work there are always more errors.

Does anybody have an idea what is the problem here? And how can I get the Coverity build without errors? Maybe I can configure Coverity to ignore c++ standard headers but I don't now how?

like image 667
Indimental Avatar asked Jan 19 '12 14:01

Indimental


People also ask

How does Coverity static analysis work?

Coverity is a static analysis tool. The starting point with Coverity is what we call central analysis. Periodically, an automated process will check out your code from your source control system and then build and analyze it with Coverity. Those results are then sent to a Coverity server.

Is coverity a SAST tool?

Coverity® is a fast, accurate, and highly scalable static analysis (SAST) solution that helps development and security teams address security and quality defects in source code early in the software development life cycle (SDLC), track and manage risks across the application portfolio, and ensure compliance with ...

What language is coverity written in?

Coverity is a static code analysis tool for C, C++, C#, Java, JavaScript, PHP, Python, .


1 Answers

Your library implementation is using C++11. Presumably there are #ifdefs that remove all the C++11 stuff when you do call g++ with -std=c++98 but it seems that however Coverity is integrated with g++, it's not defining the same things that are necessary to avoid the C++11 features.

You should figure out what the macros that gcc uses around that C++11 code are and then make sure that Coverity is defining them appropriately as well when it analyzes your project.

like image 141
bames53 Avatar answered Nov 03 '22 00:11

bames53