qqiangwu / cppsafe

Cpp lifetime safety profile static analyzer
MIT License
39 stars 1 forks source link

error: unknown type name '__BEGIN_NAMESPACE_STD' #47

Closed SteveLee123 closed 3 months ago

SteveLee123 commented 3 months ago

when I use cppsafe at my project. I got so many false positive like this. Do you have any idea about it ?

In file included from /usr/local/lib/gcc/x86_64-pc-linux-gnu/11.4.0/../../../../include/c++/11.4.0/cstdlib:75:
/usr/include/stdlib.h:95:1: error: unknown type name '__BEGIN_NAMESPACE_STD'
   95 | __BEGIN_NAMESPACE_STD
      | ^
/usr/include/stdlib.h:112:1: error: unknown type name '__END_NAMESPACE_STD'
  112 | __END_NAMESPACE_STD
      | ^
/usr/include/stdlib.h:115:22: error: expected ';' after top level declarator
  115 | __BEGIN_NAMESPACE_C99
      |                      ^
/usr/include/stdlib.h:121:5: error: a type specifier is required for all declarations
  121 |   } lldiv_t;
      |     ^
/usr/include/stdlib.h:123:1: error: unknown type name '__END_NAMESPACE_C99'
  123 | __END_NAMESPACE_C99
      | ^
/usr/include/stdlib.h:139:14: error: expected ';' after top level declarator
  139 | extern size_t __ctype_get_mb_cur_max (void) __THROW __wur;
      |              ^
/usr/include/stdlib.h:142:1: error: unknown type name '__BEGIN_NAMESPACE_STD'
  142 | __BEGIN_NAMESPACE_STD
      | ^
/usr/include/stdlib.h:152:1: error: unknown type name '__END_NAMESPACE_STD'
  152 | __END_NAMESPACE_STD
      | ^
/usr/include/stdlib.h:155:22: error: expected ';' after top level declarator
  155 | __BEGIN_NAMESPACE_C99
      |                      ^
/usr/include/stdlib.h:159:1: error: unknown type name '__END_NAMESPACE_C99'
  159 | __END_NAMESPACE_C99
      | ^
/usr/include/stdlib.h:162:22: error: expected ';' after top level declarator
  162 | __BEGIN_NAMESPACE_STD
      |                      ^
/usr/include/stdlib.h:167:1: error: unknown type name '__END_NAMESPACE_STD'
  167 | __END_NAMESPACE_STD
      | ^
qqiangwu commented 3 months ago

It's not false postives, it's just compiling failure.

The root cause is still cppsafe cannot detect your system headers. I cannot solve this without concrete environment.

Another solution is letting cmake to generate a full compile_commands.json which contains all headers paths. Add the following config to your CMakeFiles.txt

if(CMAKE_EXPORT_COMPILE_COMMANDS)
    set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
SteveLee123 commented 3 months ago

same fix as https://github.com/qqiangwu/cppsafe/issues/42#issuecomment-1994393863