Opened 12 months ago

Last modified 12 months ago

#18529 new enhancement

Intellisense warning for wxIMPLEMENT_APP

Reported by: pb101 Owned by:
Priority: low Milestone:
Component: build Version: dev-latest
Keywords: Cc: pbfordev@…
Blocked By: Blocking:
Patch: no

Description

When using MSVC 2019 (and maybe also older versions), wxIMPLEMENT_APP macro is underlined with squiggles and MSVS shows this IntelliSense C28251 warning:

Warning C28251 Inconsistent annotation for 'WinMain': this instance has no annotations. See c:\program files (x86)\windows kits\10\include\10.0.18362.0\um\winbase.h(933).

While building even the simplest possible wxWidgets application yields well over 100 IntelliSense warnings, this one is visible in the user code and may make some users worry.

Perhaps it would be worth at least suppressing the warning like this (untested):

  • include/wx/msw/init.h

     include/wx/msw/init.h | 11 +++++++++++
     1 file changed, 11 insertions(+)
    
    diff --git a/include/wx/msw/init.h b/include/wx/msw/init.h
    index eb3fead314..60b46f4c95 100644
    a b extern WXDLLIMPEXP_CORE int 
    7373    #define wxIMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
    7474#endif // defined(__BORLANDC__) && wxUSE_UNICODE
    7575
     76#if defined(__VISUALC__)
     77    // Disable IntelliSense warning C28251 "Inconsistent annotation
     78    // for 'WinMain': this instance has no annotations."   
     79    #pragma warning(push)
     80    #pragma warning (disable:28251)
     81#endif
     82
    7683#define wxIMPLEMENT_WXWIN_MAIN                                              \
    7784    extern "C" int WINAPI WinMain(HINSTANCE hInstance,                      \
    7885                                  HINSTANCE hPrevInstance,                  \
    extern WXDLLIMPEXP_CORE int 
    8996    }                                                                       \
    9097    wxIMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
    9198
     99#if defined(__VISUALC__)
     100    #pragma warning(pop)
     101#endif
     102
    92103#endif // wxUSE_GUI
    93104
    94105#endif // _WX_MSW_INIT_H_

But perhaps there is a better solution?

Change History (4)

comment:1 Changed 12 months ago by vadz

Strange, I've been using MSVS 2019 for quite some time and haven't seen this one, do I need to do anything special to see it? FWIW I do see plenty of other warnings, even just in the wx headers, but there are so many of them that are clearly bogus, that I'm not sure if it's worth fixing them. OTOH at least a few (uninitialized variables, mostly) would be worth investigating.

Anyhow, if the patch above suffices, let's apply it, but:

  1. Does it really fix the problem? I'd expect to have to use __pragma inside the macro, as the analysis warning should be given when using it, not when defining it.
  2. Don't we need to check for MSVC version? I'd expect older version to give some diagnostics about the unknown warning number.
  3. Do you understand which annotation exactly is inconsistent? I.e. could we fix this warning rather than suppressing it?

Thanks!

comment:2 Changed 12 months ago by pb101

  • Cc pbfordev@… added

Ad 1: You are correct regarding use of #pragma, my naive patch from above did not help. Using __pragma seems to help though. When doing this (just for testing, the code is obviously not for production use), the squiggles and warning disappeared

  • include/wx/msw/init.h

     include/wx/msw/init.h | 24 ++++++++++++++++++++++++
     1 file changed, 24 insertions(+)
    
    diff --git a/include/wx/msw/init.h b/include/wx/msw/init.h
    index eb3fead314..6d762415cb 100644
    a b extern WXDLLIMPEXP_CORE int 
    7373    #define wxIMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
    7474#endif // defined(__BORLANDC__) && wxUSE_UNICODE
    7575
     76#if wxCHECK_VISUALC_VERSION(14)
     77
     78#define wxIMPLEMENT_WXWIN_MAIN                                              \
     79    __pragma(warning(push))                                                 \
     80    __pragma(warning(disable:28251))                                        \
     81    extern "C" int WINAPI WinMain(HINSTANCE hInstance,                      \
     82                                  HINSTANCE hPrevInstance,                  \
     83                                  wxCmdLineArgType WXUNUSED(lpCmdLine),     \
     84                                  int nCmdShow)                             \
     85    __pragma(warning(pop))                                                  \
     86    {                                                                       \
     87        wxDISABLE_DEBUG_SUPPORT();                                          \
     88                                                                            \
     89        /* NB: We pass NULL in place of lpCmdLine to behave the same as  */ \
     90        /*     Borland-specific wWinMain() above. If it becomes needed   */ \
     91        /*     to pass lpCmdLine to wxEntry() here, you'll have to fix   */ \
     92        /*     wWinMain() above too.                                     */ \
     93        return wxEntry(hInstance, hPrevInstance, NULL, nCmdShow);           \
     94    }                                                                       \
     95
     96#else
     97
    7698#define wxIMPLEMENT_WXWIN_MAIN                                              \
    7799    extern "C" int WINAPI WinMain(HINSTANCE hInstance,                      \
    78100                                  HINSTANCE hPrevInstance,                  \
    extern WXDLLIMPEXP_CORE int 
    89111    }                                                                       \
    90112    wxIMPLEMENT_WXWIN_MAIN_BORLAND_NONSTANDARD
    91113
     114#endif // wxCHECK_VISUALC_VERSION(14)
     115
    92116#endif // wxUSE_GUI
    93117
    94118#endif // _WX_MSW_INIT_H_

Ad 2: I do not know which version introduced warning C28251, MSVC 2015 seems to have it, could not find documentation for older MSVC versions.

Ad 3: AFAICT, the issue stems from the mismatch between WinMain() prototype in wx/msw/init.h and the one in the Windows SDK which has SAL annotations:

WinMain (
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR lpCmdLine,
    _In_ int nShowCmd
    );

As for removing all those warnings, I do not know what to do. Aside from wxWidgets using drastic measures (#pragma system_header when not building the library), users probably just have to mark wxWidgets headers as external in those systems allowing for it.

See also https://devblogs.microsoft.com/cppblog/broken-warnings-theory/

comment:3 Changed 12 months ago by vadz

I think we should define wxMSVC_WARNING_SUPPRESS(num) and wxMSVC_WARNING_RESTORE() macros similar to the existing wxGCC_XXX versions and use them here. The problem is that I'm not sure what will disabling a non-existent warning do with the older MSVC versions. Our AppVeyor CI builds test MSVS as far back as 2008, so we could try it. But if it doesn't work (i.e. results in a warning of its own), we'd need to additionally define wxMSVC_ANNOTATION_WARNING_{SUPPRESS,RESTORE}() conditionally and use those macros inside wxIMPLEMENT_WXWIN_MAIN.

The only alternative would be defining our wxPARAM_{IN,INOUT,OUT}[_OPT] macros and I'm not sure it's going to be any better...

And I'm still not sure why don't I see this warning with neither test_gui nor minimal sample when I look at the "Build + IntelliSense" warnings in the "Error List" window in MSVS 2019 (again, I do see plenty of other ones).

comment:4 Changed 12 months ago by catalin

FWIW I also see that warning when compiling minimal sample with VS 2019 v16.3.2, and I don't remember seeing it with older revisions of the same compiler version

Note: See TracTickets for help on using tickets.