Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix address of function in decltype context
There is a check that tries to prevent you from taking the address of a wasm function from genericjs, or vice versa. The check uses `CurScope->getFnParent()` to get the function in which the address of operator takes place. This is not a reliable way to get the current function declaration, and its usage here allows some invalid code to sneak past the check. #include <cheerp/clientlib.h> struct functor { [[cheerp::wasm]] void wasm_func() {} }; template<class T> [[cheerp::genericjs]] auto js_func() -> void(functor::*)() { return &T::wasm_func; // address of wasm function here } [[cheerp::genericjs]] int main() { client::console.log(js_func<functor>()); } `getCurFunctionDecl()` is a more reliable way to get the current function declaration, and using it, the above code no longer compiles (yay!). There is one place in `cheerp/client.h` where the address of a wasm function is taken from inside a decltype expression in the return type of a genericjs function. Because the operand of a decltype expression is never evaluated, we can always allow taking the address of a function like this as long as it happens in a decltype expression. And, this way, there is no issue in `cheerp/client.h`.
- Loading branch information