Menu

#1565 Add noexcept to COM methods

Initial
closed
nobody
5
2025-11-11
2025-07-15
mberchtold
No

This patch adds noexcept to COM interface methods. Typically these are methods with a HRESULT return type, which are not supposed to throw any exceptions. Adding noexcept reduces the number of unwind states.

Affected files:
win32/ScintillaWin.cxx
win32/SurfaceD2D.cxx

1 Attachments

Discussion

  • Neil Hodgson

    Neil Hodgson - 2025-07-16

    I think I looked at this before and there were hassles with deriving noexcept from an interface defined as potentially throwing. As well as Microsoft's interface definitions, there are open source versions and even Microsoft isn't consistent.

     
  • Zufu Liu

    Zufu Liu - 2025-07-16
    • labels: --> Scintilla, win32
     
  • mberchtold

    mberchtold - 2025-07-19

    What specific issues did you encounter? Adding noexcept to COM methods which are final (all the ones in the patch) shouldn't cause any. Some of them (not all) are already annotated with the Microsoft specific declspec(nothrow) attribute.

     
    • Neil Hodgson

      Neil Hodgson - 2025-09-27

      Tried patch with MinGW 13.2 on Win32 and see:

      g++ -DNDEBUG -I ../include -I ../src --std=c++17 -Wpedantic -Wall -Wextra -Wconversion -O3  -c SurfaceD2D.cxx -o SurfaceD2D.o
      SurfaceD2D.cxx:963:48: error: declaration of 'virtual HRESULT {anonymous}::BlobInline::Draw(void*, IDWriteTextRenderer*, FLOAT, FLOAT, BOOL, BOOL, IUnknown*)' has a different exception specifier
        963 | COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE BlobInline::Draw(
            |                                                ^~~~~~~~~~
      SurfaceD2D.cxx:918:43: note: from previous declaration 'virtual HRESULT {anonymous}::BlobInline::Draw(void*, IDWriteTextRenderer*, FLOAT, FLOAT, BOOL, BOOL, IUnknown*) noexcept'
        918 |         COM_DECLSPEC_NOTHROW STDMETHODIMP Draw(
            |                                           ^~~~
      SurfaceD2D.cxx:977:48: error: declaration of 'virtual HRESULT {anonymous}::BlobInline::GetMetrics(DWRITE_INLINE_OBJECT_METRICS*)' has a different exception specifier
        977 | COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE BlobInline::GetMetrics(
            |                                                ^~~~~~~~~~
      SurfaceD2D.cxx:927:43: note: from previous declaration 'virtual HRESULT {anonymous}::BlobInline::GetMetrics(DWRITE_INLINE_OBJECT_METRICS*) noexcept'
        927 |         COM_DECLSPEC_NOTHROW STDMETHODIMP GetMetrics(DWRITE_INLINE_OBJECT_METRICS *metrics) noexcept override;
            |                                           ^~~~~~~~~~
      SurfaceD2D.cxx:989:48: error: declaration of 'virtual HRESULT {anonymous}::BlobInline::GetOverhangMetrics(DWRITE_OVERHANG_METRICS*)' has a different exception specifier
        989 | COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE BlobInline::GetOverhangMetrics(
            |                                                ^~~~~~~~~~
      SurfaceD2D.cxx:928:43: note: from previous declaration 'virtual HRESULT {anonymous}::BlobInline::GetOverhangMetrics(DWRITE_OVERHANG_METRICS*) noexcept'
        928 |         COM_DECLSPEC_NOTHROW STDMETHODIMP GetOverhangMetrics(DWRITE_OVERHANG_METRICS *overhangs) noexcept override;
            |                                           ^~~~~~~~~~~~~~~~~~
      SurfaceD2D.cxx:1001:48: error: declaration of 'virtual HRESULT {anonymous}::BlobInline::GetBreakConditions(DWRITE_BREAK_CONDITION*, DWRITE_BREAK_CONDITION*)' has a different exception specifier
       1001 | COM_DECLSPEC_NOTHROW HRESULT STDMETHODCALLTYPE BlobInline::GetBreakConditions(
            |                                                ^~~~~~~~~~
      SurfaceD2D.cxx:929:43: note: from previous declaration 'virtual HRESULT {anonymous}::BlobInline::GetBreakConditions(DWRITE_BREAK_CONDITION*, DWRITE_BREAK_CONDITION*) noexcept'
        929 |         COM_DECLSPEC_NOTHROW STDMETHODIMP GetBreakConditions(
            |                                           ^~~~~~~~~~~~~~~~~~
      mingw32-make: *** [makefile:75: SurfaceD2D.o] Error 1
      mingw32-make: *** Waiting for unfinished jobs....
      checkbuilds.bat:1: Failed 2
      
       
  • Neil Hodgson

    Neil Hodgson - 2025-11-11
    • status: open --> closed
     
  • Neil Hodgson

    Neil Hodgson - 2025-11-11

    Closing since the approach fails with at least one build setup.

     

Log in to post a comment.