r/cpp • • Oct 17 '26

I can't use generic lambdas at compile-time, now what? - Braden Ganetsky

https://blog.ganets.ky/ClangGenericLambdas/
28 Upvotes

11 comments sorted by

3

u/tialaramex Oct 18 '26

While the examples involved requires it seemed pretty ordinary (for a bug) to me because requires very easily gets you IFNDR which is profound level of doom. This area is haunted, no surprise there are (also?) bugs.

The (new?) reduction to not involve requires changes that and seems more concerning. Do you have a link to the Clang/ LLVM bug - I didn't see one in the article but it's entirely possible I missed it.

5

u/not_a_novel_account cmake dev Oct 18 '26

The bug is old enough to start learning long division:

https://github.com/llvm/llvm-project/issues/35052

3

u/_yrlf Oct 20 '26

Yeah, that area of the clang code seems pretty broken.

I've recently fixed a different bug related to consteval lambdas in Clang (https://github.com/llvm/llvm-project/issues/183415 and https://github.com/llvm/llvm-project/issues/169139, bug from 2025) and from what I found out there there is much much more to fix in this area. I think the ways used to propagate consteval-ness and constexpr-ness are pretty brittle and require too many specific checks in many places that are easily forgotten or done wrong.

1

u/k3DW Oct 22 '26

That's amazing, thank you for the fix! #169139 was my bug. It looks like a thorny area of the code. I certainly wouldn't have known how to fix it

2

u/_yrlf Oct 22 '26

I actually just looked at this bug because I also ran into it and thought "how hard can it be to fix a clang bug?". It was actually my second ever attempted time to fix something in LLVM.

The Clang codebase is surprisingly easy to hack on! (You should compile clang with clang and lld though, otherwise (with gcc) you get a 150GB build folder and probably OOM during linking)

1

u/k3DW Oct 23 '26

Nice, that's great to hear! Maybe I'll find the time one day to try working on #35052. And given your success here, maybe you should too! ;)

Last time I compiled Clang, I believe I did it with GCC, and yes I did end up with a horrifically large build folder. Thanks for the tip

1

u/_yrlf Oct 23 '26

With clang the build folder is at least a third as small (only ~50GB). It also helps to compile only the host target (e.g. x86_64) and to limit the amount of parallel linking steps to avoid going OOM.

Then, after you have an initial build, a recompile only takes a minute or so.

2

u/k3DW Oct 18 '26

This area is definitely haunted. Thanks for linking the bug here. I realize I did link the bug in my previous article, but forgot to do it in this one. I'll add the link

-1

u/Business-Weather-217 Oct 18 '26

I suspect this is intentional and the advantage of this might be that it uses runtime type erasure just like go, unlike cpp/rust templates which usually has enormous compile times. It's casually dufus opinion of mine, i think cppreference covers it or else it begs the question: how all compilers chose to do the same thing?

6

u/k3DW Oct 18 '26

If I'm understanding you correctly, you're saying that it might be intentional that Clang can't execute generic lambdas at compile-time. I'm pretty sure that this isn't true, since there's nothing in the standard forbidding it, the bug I logged with LLVM was recognized to be a real bug. It works in the other compilers, but writing a compiler is extremely difficult, and edge cases may slip through

4

u/tzlaine Oct 18 '26

And there's no runtime type erasure.