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

I use the Wind River Compiler 4 compiler (gcc (C) and g ++ (C ++)) and it will compile all my projects without problems. Now I have to use Static Analysis to check the code. I configured specific compilers. There are no problems for C code (gcc), and I can start the analysis, but for 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 seems that some C ++ 11 specific functions, such as the built-in namespace, but the code does not use these functions. The errors mentioned above are generated using 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 tried to set the C ++ standard with the g ++ option

 -std=c++98 

but the result has not changed.

Test-Code is in a large build hierarchy, but the steps for Coverity are as follows:

  • target and env set (Wind River 4 Linux)
  • make clean
  • cov-configure with parameter and compiler type
  • cov-build with the right do-it-all command that works on its own
  • SOU analysis
  • if (no_error) cov-commit-errors

I also created Coverity to replace the entire "built-in namespace" with a "namespace" during cov-build ( --ppp-translator replace/inline namespace/namespace ). Inline errors have disappeared, but it causes more errors during overload and without failures. Also tried to remove "C ++" in the same way, but did not work, there are always more errors.

Does anyone have any idea what the problem is? And how can I get Coverity build without errors? Maybe I can configure Coverity to ignore the standard C ++ headers, but now I don’t know how to do this?

+7
source share
3 answers

Coverity Support Workaround :

The built-in namespace is a known bug in Coverity. To get around it, configure Coverity with the following additional parameters (in the configuration file):

  <begin_command_line_config></begin_command_line_config> <add-arg>--ppp_translator</add_arg> <add_arg>replace/inline namespace ([_a-zA-Z0-9]*)\s+\{\s*\}/namespace $1 { } using namespace $1;</add_arg> </options> 

After that, we got some other errors, but they seem to belong to all string definitions. Now add the definition of Coverity at the beginning of coverity-compiler-compat.h (also in the config directory):

 #define __COVERITY_NO_STRING_NODEFS__ 

After these changes, cov-build works without errors and analysis can be started.

+4
source

Your library implementation uses C ++ 11. Supposedly there are #ifdefs that remove all C ++ 11 stuff when you call g ++ with -std=c++98 , but it seems that although Coverity is integrated with g ++, it does not define the same things that are necessary to avoid C ++ 11 functions.

You need to figure out what macros gcc uses around this C ++ 11 code, and then make sure Coverity also correctly defines them when it parses your project.

+5
source

This error says it quite clearly:

built-in specifier allowed only for function declarations

Is there a reason the inline namespace is? Although I do not have a specification, so I can not say whether it is allowed or not. (The fact that the compiler resolves this may be a bug in GCC.)

Try removing this inline , and Coverity will hopefully be happy.

It seems that Coverity has not been updated with some C ++ 11 features such as inline namespaces.

0
source

All Articles