A C++ tool that performs compile-time unit testing ran into a Clang compiler bug that prevents generic lambdas from being evaluated at compile-time. A minimal repro shows generic lambdas used with consteval cannot be instantiated in Clang (issues tracked in the LLVM project), which breaks an API that needs to dispatch between nullary and stateful "packet" invocables inside a macro. The dispatch originally used if constexpr on decltype-based checks, but when the macro expands in a non-template (non-dependent) context the compiler eagerly semantically checks all branches, causing hard errors for invocations that should be rejected. The author also reports travel and talks at CppCon and NDC TechTown as background.
The practical workaround is to create a dependent template context without relying on compile-time generic lambdas. Wrapping logic in an immediately-invoked generic lambda would usually create dependence, but Clang’s bug prevents that from working at consteval. Instead, moving the conditional invocation into a proper function template (example: invoke_packet_nullary) preserves the desired behavior: the template-only branch is only valid when invocable, and Clang accepts it. This approach allows the macro-based dispatch to avoid compile-time failures while still supporting both nullary and stateful packet semantics.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.