Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138095

The QMacApperanceStyle<QMacStyle> template instantiation in QMacStyle::create() triggers a clang compiler crash

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.11
    • Active Qt
    • None
    • Qt 6.11.0 clang 21.0.0git Host: Linux (WSL2) Target: x86_64-apple-darwin24.5 Build system: CMake + Ninja
    • macOS
    • macOS

    Description

      Error Details

      Compiler Crash

      clang++: /home/mccakit/llvm-project/clang/lib/Sema/TreeTransform.h:17056: 
      clang::ExprResult clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformBlockExpr(clang::BlockExpr *) 
      [Derived = (anonymous namespace)::TemplateInstantiator]
      Assertion `(!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) && 
      "this pointer isn't captured in the old block"' failed.

      Problematic Code

      Template Definition

      template<typename Style>
      class QMacApperanceStyle : public Style
      {
      public:
          void drawPrimitive(typename Style::PrimitiveElement pe, const QStyleOption *opt, QPainter *p
                             OPTIONAL_WIDGET_ARGUMENT) const override
          {
              [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^

      {             Style::drawPrimitive(pe, opt, p                 FORWARD_OPTIONAL_WIDGET_ARGUMENT);         }

      ];
          }
          // ... similar methods for drawControl and drawComplexControl
      };

      Instantiation Site

      QMacStyle *QMacStyle::create()

      {     return new QMacApperanceStyle<QMacStyle>; // <- Causes compiler crash }

      Proposed Solutions

      Option 1: Fix Template Capture

      Modify the template to explicitly handle this capture:

      void drawPrimitive(typename Style::PrimitiveElement pe, const QStyleOption *opt, QPainter *p
                         OPTIONAL_WIDGET_ARGUMENT) const override
      {
          const auto* self = this;
          [NSApp.effectiveAppearance performAsCurrentDrawingAppearance:^

      {         self->Style::drawPrimitive(pe, opt, p             FORWARD_OPTIONAL_WIDGET_ARGUMENT);     }

      ];
      }

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            owolff Oliver Wolff
            mccakit Mehmet Can Çakıt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes