Menu

Cppcheck 2.0 Windows sometimes can not resolve the TEXT macro

Zufu Liu
2020-05-18
2020-05-19
  • Zufu Liu

    Zufu Liu - 2020-05-18

    The sample file is at https://github.com/zufuliu/notepad2/blob/master/src/Dialogs.c#L260

    F:\Libs\notepad2\src>cppcheck Dialogs.c
    Checking Dialogs.c ...
    Dialogs.c:260:37: error: There is an unknown macro here somewhere. Configuration is required. If TEXT is a macro then please configure it. [unknownMacro]
      SetDlgItemText(hwnd, IDC_VERSION, VERSION_FILEVERSION_LONG);
                                        ^
    Checking Dialogs.c: APSTUDIO_INVOKED...
    Checking Dialogs.c: NP2_FORCE_COMPILE_C_AS_CPP=0...
    Checking Dialogs.c: VERSION_BUILD_TOOL_BUILD...
    Checking Dialogs.c: _ARM64_;_M_ARM64;__aarch64__;_WIN64...
    Checking Dialogs.c: _ARM_;_M_ARM;__arm__...
    Checking Dialogs.c: _IA64_;_M_IA64;__ia64__;_WIN64...
    Checking Dialogs.c: _MSC_VER...
    Checking Dialogs.c: _WIN64...
    Checking Dialogs.c: _WIN64;__AVX2__...
    Checking Dialogs.c: __GNUC__...
    Checking Dialogs.c: __GNUC__;__NO_INLINE__...
    nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs]
    

    where VERSION_FILEVERSION_LONG is defiend at https://github.com/zufuliu/notepad2/blob/master/src/Version.h#L94

    #define DO_STRINGIFY(x)     TEXT(#x)
    #define STRINGIFY(x)        DO_STRINGIFY(x)
    
    // others
    #define VERSION_FILEVERSION_LONG    MY_APPNAME VERSION_FILEVERSION_ARCH STRINGIFY(VERSION_MAJOR) L"." \
                                        STRINGIFY(VERSION_MINOR) L"." STRINGIFY(VERSION_BUILD) \
                                        L" " VERSION_REV_FULL
    

    however, directly use SetDlgItemText(hwnd, TEXT("string")) works.

     
  • Zufu Liu

    Zufu Liu - 2020-05-18

    reduced test case:

    #include <windows.h>
    
    #define DO_STRINGIFY(x) TEXT(#x)
    #define STRINGIFY(x)    DO_STRINGIFY(x)
    #define VERSION_MAJOR   4
    #define VERSION_TEXT    L"prefix" STRINGIFY(VERSION_MAJOR) L"suffix"
    
    void UpdateText(HWND hwnd) {
        SetWindowText(hwnd, VERSION_TEXT);
    }
    
    cppcheck.exe test.c
    Checking test.c ...
    test.c:9:25: error: There is an unknown macro here somewhere. Configuration is required. If TEXT is a macro then please configure it. [unknownMacro]
        SetWindowText(hwnd, VERSION_TEXT);
    

    it works after delete L"prefix" or L"suffix" from VERSION_TEXT.

     
  • Daniel Marjamäki

    Please try --library=windows.

     
  • Daniel Marjamäki

    If you use visual studio then I would suggest that you use the solution/project files for that ..

    For instance:

    cppcheck --project=notepad2.sln

    I have the feeling that --library=windows is not needed then.

     
  • Zufu Liu

    Zufu Liu - 2020-05-19

    Both not works, that's why I try clang.
    following is https://github.com/zufuliu/notepad2/blob/master/Notepad2.cppcheck

    <?xml version="1.0" encoding="UTF-8"?>
    <project version="1">
        <platform>win64</platform>
        <importproject>build/VS2017/Notepad2.sln</importproject>
        <analyze-all-vs-configs>true</analyze-all-vs-configs>
        <check-headers>true</check-headers>
        <check-unused-templates>false</check-unused-templates>
        <max-ctu-depth>10</max-ctu-depth>
        <libraries>
            <library>windows</library>
        </libraries>
    </project>
    

    test.c works with Cppcheck 1.90, this is a regression change between 1.90 and 2.00.
    For Notepad2, Cppcheck 1.90 only has the AST broken error, no unknownMacro for TEXT.

     
  • Daniel Marjamäki

    ok I tried that also now.. and I can reproduce, this is not working well. :-(

     
  • Daniel Marjamäki

    I have created this Trac ticket: https://trac.cppcheck.net/ticket/9730

     

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.