FWIW @Douglas_Gregor had objections when we discussed this back in 2020 when async/await was first introduced: SE-0296: async/await - #77 by Douglas_Gregor .
Banning
awaitinsidedeferseems like an artificial restriction, so it seems easy to lift?Perhaps, but I don't think it fits well with the goals of the proposal. It means having potential suspension points that are somewhat arbitrary, e.g., at every
tryandreturnwhere there is such adefer, you would have an implicit potential suspension point.What do you mean by “arbitrary”?
deferis conceptually just code that runs at the end of the function. I see why it has special behavior with regards totry: we want to avoid nested error throwing. I don’t see why it should have special behavior with regards toawait.It turns any try, throw, or return when there is an active async defer into an implicit “await”. That seems reason enough not to support it.