<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/115931>115931</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang]  Assertion `((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) || S.getCurGenericLambda()) && "The capture ready lambda for a potential capture can only be the " "current lambda if it is a generic lambda"' failed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          aperezdc
      </td>
    </tr>
</table>

<pre>
    This was found building WebKitGTK at commit https://github.com/WebKit/WebKit/commit/d9758a8fd190860ac6c4a468dfdea906786530e5

Clang was built using [this PKGBUILD for Arch Linux](https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=clang-prefixed-release).

Stack dump:

```
clang++: /usr/src/debug/clang-prefixed-release/llvm-project-llvmorg-19.1.2/clang/lib/Sema/SemaLambda.cpp:195: std::optional<unsigned int> clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(ArrayRef<const sema::FunctionScopeInfo *>, ValueDecl *, Sema &): Assertion `((IndexOfCaptureReadyLambda != (FunctionScopes.size() - 1)) || S.getCurGenericLambda()) && "The capture ready lambda for a potential capture can only be the " "current lambda if it is a generic lambda"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/clang/latest/bin/clang++ -Wextra -Wall -Werror=undefined-internal -Werror=undefined-inline -pipe -Wno-noexcept-type -Wno-psabi -Wno-misleading-indentation -Wno-parentheses-equality -Qunused-arguments -Wundef -Wpointer-arith -Wmissing-format-attribute -Wformat-security -Wcast-align -Wno-tautological-compare -fasynchronous-unwind-tables -fdebug-types-section -fno-strict-aliasing -fno-exceptions -fno-rtti -fcoroutines -ffunction-sections -fdata-sections -O3 -std=c++23 -fPIC -fvisibility=hidden -pthread -mfpmath=sse -msse -msse2 -fdiagnostics-color=always -fcolor-diagnostics -DBUILDING_GTK__=1 -DBUILDING_WEBKIT=1 -DBUILDING_WITH_CMAKE=1 -DBUILDING_WebCore -DBWRAP_EXECUTABLE=\"/usr/bin/bwrap\" -DDBUS_PROXY_EXECUTABLE=\"/usr/bin/xdg-dbus-proxy\" -DGETTEXT_PACKAGE=\"WebKitGTK-6.0\" -DHAVE_CONFIG_H=1 -DJSC_GLIB_API_ENABLED -DPAS_BMALLOC=1 -DSK_ASSUME_GL=0 -DSK_ASSUME_GL_ES=1 -DSK_ASSUME_WEBGL=0 -DSK_DISABLE_LEGACY_GL_MAKE_NATIVE_INTERFACE -DSK_DISABLE_LEGACY_IMAGE_READBUFFER -DSK_DISABLE_LEGACY_INIT_DECODERS -DSK_DISABLE_LEGACY_PNG_WRITEBUFFER -DSK_DISABLE_TRACING -DSK_DISABLE_WEBGL_INTERFACE -DSK_ENABLE_PRECOMPILE -DSK_R32_SHIFT=16 -DSK_RELEASE -DSK_TRIVIAL_ABI=[[clang::trivial_abi]] -DSTATICALLY_LINKED_WITH_PAL -DUSE_SYSTEM_EGL -I. -IWebCore/DerivedSources -I../Source/WebCore -I../Source/WebCore/Modules/ShapeDetection -I../Source/WebCore/Modules/ShapeDetection/Interfaces -I../Source/WebCore/Modules/WebGPU -I../Source/WebCore/Modules/WebGPU/InternalAPI -I../Source/WebCore/Modules/WebGPU/Implementation -I../Source/WebCore/Modules/airplay -I../Source/WebCore/Modules/applepay -I../Source/WebCore/Modules/applepay/paymentrequest -I../Source/WebCore/Modules/applicationmanifest -I../Source/WebCore/Modules/async-clipboard -I../Source/WebCore/Modules/audiosession -I../Source/WebCore/Modules/badge -I../Source/WebCore/Modules/beacon -I../Source/WebCore/Modules/cache -I../Source/WebCore/Modules/compression -I../Source/WebCore/Modules/contact-picker -I../Source/WebCore/Modules/cookie-consent -I../Source/WebCore/Modules/cookie-store -I../Source/WebCore/Modules/credentialmanagement -I../Source/WebCore/Modules/encryptedmedia -I../Source/WebCore/Modules/encryptedmedia/legacy -I../Source/WebCore/Modules/entriesapi -I../Source/WebCore/Modules/fetch -I../Source/WebCore/Modules/filesystemaccess -I../Source/WebCore/Modules/geolocation -I../Source/WebCore/Modules/highlight -I../Source/WebCore/Modules/identity -I../Source/WebCore/Modules/indexeddb -I../Source/WebCore/Modules/indexeddb/client -I../Source/WebCore/Modules/indexeddb/server -I../Source/WebCore/Modules/indexeddb/shared -I../Source/WebCore/Modules/mediacapabilities -I../Source/WebCore/Modules/mediacontrols -I../Source/WebCore/Modules/mediarecorder -I../Source/WebCore/Modules/mediasession -I../Source/WebCore/Modules/mediasource -I../Source/WebCore/Modules/mediastream -I../Source/WebCore/Modules/model-element -I../Source/WebCore/Modules/model-element/dummy -I../Source/WebCore/Modules/navigatorcontentutils -I../Source/WebCore/Modules/notifications -I../Source/WebCore/Modules/paymentrequest -I../Source/WebCore/Modules/permissions -I../Source/WebCore/Modules/pictureinpicture -I../Source/WebCore/Modules/plugins -I../Source/WebCore/Modules/push-api -I../Source/WebCore/Modules/remoteplayback -I../Source/WebCore/Modules/reporting -I../Source/WebCore/Modules/screen-wake-lock -I../Source/WebCore/Modules/speech -I../Source/WebCore/Modules/storage -I../Source/WebCore/Modules/streams -I../Source/WebCore/Modules/url-pattern -I../Source/WebCore/Modules/web-locks -I../Source/WebCore/Modules/webaudio -I../Source/WebCore/Modules/webauthn -I../Source/WebCore/Modules/webauthn/cbor -I../Source/WebCore/Modules/webauthn/fido -I../Source/WebCore/Modules/webcodecs -I../Source/WebCore/Modules/webdatabase -I../Source/WebCore/Modules/webdriver -I../Source/WebCore/Modules/websockets -I../Source/WebCore/Modules/webtransport -I../Source/WebCore/Modules/webxr -I../Source/WebCore/accessibility -I../Source/WebCore/accessibility/isolatedtree -I../Source/WebCore/animation -I../Source/WebCore/bin
1.      <eof> parser at end of file
2. ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:112:33: instantiating function definition 'WebCore::Style::reflectSum<Range{-INF, INF}, Range{0.000000e+00, INF}>'
3. ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes.h:679:44: instantiating function definition 'WebCore::Style::LengthPercentageValue<Range{0.000000e+00, INF}>::switchOn<(lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:132:13), (lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:136:13)>'
4. ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes.h:666:41: instantiating function definition 'WebCore::Style::LengthPercentageValue<Range{0.000000e+00, INF}>::visit<WTF::Visitor<(lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:132:13), (lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:136:13)>>'
5. /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:3143:12: instantiating class definition 'std::invoke_result<WTF::Visitor<(lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:132:13), (lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:136:13)>, WebCore::Style::Length<Range{0.000000e+00, INF}>>'
6. /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:2656:12: instantiating class definition 'std::__invoke_result<WTF::Visitor<(lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:132:13), (lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:136:13)>, WebCore::Style::Length<Range{0.000000e+00, INF}>>'
7. /usr/lib64/gcc/x86_64-pc-linux-gnu/14.2.1/../../../../include/c++/14.2.1/type_traits:2618:12: instantiating class definition 'std::__result_of_impl<false, false, WTF::Visitor<(lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:132:13), (lambda at ../Source/WebCore/style/values/primitives/StylePrimitiveNumericTypes+Evaluation.h:136:13)>, WebCore::Style::Length<Range{0.000000e+00, INF}>>'
 #0 0x00007fa491b8a67d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/clang/19.1.2/bin/../lib/libLLVM.so.19.1+0x458a67d)
 #1 0x00007fa491b89469 llvm::sys::RunSignalHandlers() (/opt/clang/19.1.2/bin/../lib/libLLVM.so.19.1+0x4589469)
 #2 0x00007fa491aac134 (/opt/clang/19.1.2/bin/../lib/libLLVM.so.19.1+0x44ac134)
 #3 0x00007fa48d35d1d0 (/usr/lib/libc.so.6+0x3d1d0)
 #4 0x00007fa48d3b63f4 (/usr/lib/libc.so.6+0x963f4)
 #5 0x00007fa48d35d120 raise (/usr/lib/libc.so.6+0x3d120)
 #6 0x00007fa48d3444c3 abort (/usr/lib/libc.so.6+0x244c3)
 #7 0x00007fa48d3443df (/usr/lib/libc.so.6+0x243df)
 #8 0x00007fa48d355177 (/usr/lib/libc.so.6+0x35177)
 #9 0x00007fa49954fd4f clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(llvm::ArrayRef<clang::sema::FunctionScopeInfo const*>, clang::ValueDecl*, clang::Sema&) (/opt/clang/19.1.2/bin/../lib/libclang-cpp.so.19.1+0x274fd4f)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.1.2
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/clang/19.1.2/bin
Build config: +assertions
```

I have zipped the source and run script because the source is huge and GitHub wouldn't take it otherwise: [source-and-runscript.zip](https://github.com/user-attachments/files/17721641/source-and-runscript.zip)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWlt346iy_jXkhSUvG_n6kAdZltM-cad9Yndn5kkLQUnmRAZtQEk8v_4skJLY6UyP0nv2zMOeXmlZgrp8FEVxK2qMKCTAJRrN0WhxQWu7V_qSVqDhN84uMsWPl7u9MPiRGpyrWnKc1aLkQhb4DrJ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