r/cpp • • May 09 '26

Any good tech talks leveraging statement expressions?

Lambdas do a great job in a lot of cases but sometimes you need a statement expression. Any good content on youtube?

12 Upvotes

33 comments sorted by

View all comments

Show parent comment

2

u/erichkeane Clang Maintainer(Templates), EWG Chair May 09 '26

You understate the weirdy issues with temporaries :) They are a GCC extension that we have in Clang, but their effect on lifetime is absolutely absurd, to the point that they become very difficult to use in C++ correctly very quickly.

1

u/javascript May 09 '26

Great to hear from someone with expertise!

Is my implementation of the MY_TRY macro elsewhere in this thread sufficient for day to day use? Or are there footguns?

1

u/erichkeane Clang Maintainer(Templates), EWG Chair May 09 '26

I'd have to page in all the problems with them again, I haven't poked at them in a few years.

But my rule of thumb at one point was to never have a lifetime with side effects start in a statement expression, and definitely never do multiple returns when you do.