llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.11k stars 12.01k forks source link

Factor `Error` and `Expected` boilerplate return-macros #92054

Open mtrofin opened 6 months ago

mtrofin commented 6 months ago

Examples: RETURN_IF_ERROR and ASSIGN_OR_RETURN or these with a slightly different name.

The idea is to place them in Error.h

mtrofin commented 6 months ago

FWIW, it may be more tricky than it seems. The Error case is straightforward, the Expect<T> isn't. In the OutputSizeLimitTest.cpp example, the goal is to assign Var to *Expect, while in the ResourceScriptParser.cpp example, Var gets assigned Expect. Then, here it gets more interesting, with references and const references.

Maybe we end up with a few macros, but then again, maybe having these macros n-plicated isn't so bad afterall.

Also: