VS 2022 error – incompatible exception specification for virtual functions “CPrintDialogEx::Release” and IPrintDialogCallback

I have a big dll library used MFC and Autocad ARX SDK. If I compile it, compiler throw error:
E0766 – exception specification for virtual function “CPrintDialogEx::Release” is incompatible with that of overridden function “IPrintDialogCallback::Release”

They both are a standard MFC or windows library:
first in commdlg.h:

DECLARE_INTERFACE_IID_(IPrintDialogCallback, IUnknown, "5852A2C3-6530-11D1-B6A3-0000F8757BF9")
{
    // *** IUnknown methods ***
    STDMETHOD(QueryInterface) (THIS_ _In_ REFIID riid, _Outptr_ void **ppvObj) PURE;
    STDMETHOD_(ULONG, AddRef) (THIS) PURE;
    STDMETHOD_(ULONG, Release)(THIS) PURE;

    // *** IPrintDialogCallback methods ***
    STDMETHOD(InitDone) (THIS) PURE;
    STDMETHOD(SelectionChange) (THIS) PURE;
    STDMETHOD(HandleMessage) (THIS_ HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, 
    LRESULT *pResult) PURE;
};

(macro STDMETHOD expands to:

virtual __declspec(nothrow) HRESULT __stdcall QueryInterface

and second in afxdlgs.h:

        class CPrintDialogEx :
        public CCommonDialog,
        public IPrintDialogCallback,
        public IObjectWithSite
        {   ....
              STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
              virtual ULONG STDMETHODCALLTYPE AddRef();
              virtual ULONG STDMETHODCALLTYPE Release();
               ...
        };

And most interesting is that this error shows only if I have some other error in my code.
If I fix all my own bugs, compiler compile code without error.

When I used VS 2019, I had not problem with it.

Is it VS2022 bug or something else?

Illustration screenshot

  • Perhaps this change affects the code? Starting with C++17, the noexcept specifier is a part of the function type.

    – 

  • 1

    I remember I’ve seen similar error messages with my code base. They are not from the compiler but from the editor (the error number starts with an E) and they are false positives. As soon as you get rid of the actual errors (error numbers starting with a C, like C2039 'GetSklonPriopoiky': is not a member of 'CMaiPripoika' in your case) they should go away. It’s a Microsoft bug and you can basically ignore these errors.

    – 




Leave a Comment