Menu

Can cppcheck pre-processor consider definitions?

now3d
2023-12-09
2023-12-14
  • now3d

    now3d - 2023-12-09

    I noticed some invalid warnings, after a #define, it then complains about an #if

    ifndef MYDEF

    define MYDEF 1

    endif

    if MYDEF /// cppcheck error here

    //

    endif

     
  • Daniel Marjamäki

    Can you clarify what problem you have? Here is what happens when I try with latest release:

    $ cppcheck-2.12.0 123.c 
    Checking 123.c ...
    Active checkers: 4/565
    $ cat 123.c 
    
    #ifndef MYDEF
    #define MYDEF 1
    #endif
    #if MYDEF /// cppcheck error here
    
    //
    #endif
    
     
  • now3d

    now3d - 2023-12-14

    Hi Daniel

    Sorry I should have given an example. This is just compiling using g++ some C++ code that uses pretty regular headers from the compiler and standard library

    $ make cppcheck
    cppcheck -q -v -I./src -I/usr/include -I/usr/include/x86_64-linux-gnu -I/usr/include/i386-linux-gnu -I/usr/include/c++/13 -I/usr/include/x86_64-linux-gnu/c++/13 -I/usr/lib/gcc/x86_64-linux-gnu/13/include --force --enable=information  src/*.cpp
    cppcheck: '--enable=information' will no longer implicitly enable 'missingInclude' starting with 2.16. Please enable it explicitly if you require it.
    /usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:54:0: information: Include file: <sys/_types.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    #include <sys/_types.h>
    ^
    /usr/lib/gcc/x86_64-linux-gnu/13/include/stddef.h:50:0: information: Include file: <machine/ansi.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    #include <machine/ansi.h>
    ^
    /usr/include/x86_64-linux-gnu/gnu/stubs.h:13:0: information: Include file: <gnu/stubs-x32.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    # include <gnu/stubs-x32.h>
    ^
    /usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:873:0: error: failed to evaluate #if condition, division/modulo by zero [preprocessorErrorDirective]
    # if _GLIBCXX_USE_TBB_PAR_BACKEND
    ^
    '' : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    F_LOCK;_SYS_SELECT_H : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    F_LOCK;__REDIRECT;_SYS_SELECT_H : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    HAVE_SCHED_H;_LIBOBJC : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    L_SET;_SYS_SELECT_H : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    MB_LEN_MAX : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    NAME_MAX;__USE_MISC;__USE_XOPEN2K8;_SYS_SELECT_H : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    PSTL_USAGE_WARNINGS;_SYS_SELECT_H : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    PSTL_USE_NONTEMPORAL_STORES;_SYS_SELECT_H : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    PTHREAD_RECURSIVE_MUTEX_INITIALIZER : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    WINNT;__BSD_NET2__;__FreeBSD__;____386BSD____;__bsdi__;__sequent__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_SOURCE;_ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_BSD_RUNE_T_ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_SOURCE;_ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_BSD_RUNE_T_;__FreeBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_SOURCE;_ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;__BSD_VISIBLE;__FreeBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_SOURCE;_ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;__FreeBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_BSD_PTRDIFF_T_;_PTRDIFF_T_;__NetBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_BSD_RUNE_T_ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_BSD_SIZE_T_;_SIZE_T_;__NetBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_BSD_WCHAR_T_;_WCHAR_T_;__NetBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_GCC_PTRDIFF_T_;__NetBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_GCC_SIZE_T_;__NetBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_GCC_WCHAR_T_;__NetBSD__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_PTRDIFF_T_;__sequent__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_TYPE_ptrdiff_t;__need_ptrdiff_t : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_TYPE_size_t : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;_TYPE_wchar_t : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    _ANSI_STDDEF_H;_STDDEF_H;_STDDEF_H_;__STDDEF_H__;__need_ptrdiff_t;__need_wint_t;__BEOS__ : [/usr/include/c++/13/bits/requires_hosted.h:34] #error "This header is not available in freestanding mode."
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.