emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.91k stars 3.32k forks source link

embind: no matching member function for call to 'function' #15168

Closed everywill closed 2 years ago

everywill commented 3 years ago

It seems with a specific name link 'open', embind fails to compile width message - error: no matching member function for call to 'function'. The error did not occur before I update emsdk to latest version.

code is like:

bool open(XEncoder& self) {
    int openResult = self.open();
    if (openResult == X_CODE_OK) {
        return true;
    }
    return false;
}
EMSCRIPTEN_BINDINGS(decoder_module) {
     class_<XEncoder>("XEncoder")
        .constructor(&makeXEncoder, allow_raw_pointers())
        .function("open", &open)
        ;
 }

and error message:

../XEncoderBinding.cpp:88:10: error: no matching member function for call to 'function'
        .function("open", &open)
        ~^~~~~~~~
/Users/gaoding/github/emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:1567:44: note: candidate template ignored: couldn't infer template argument 'Callable'
    EMSCRIPTEN_ALWAYS_INLINE const class_& function(const char* methodName, Callable callable, Policies...) const {
                                           ^
1 error generated.
emcc: error: '/Users/gaoding/github/emsdk/upstream/bin/clang++ -target wasm32-unknown-emscripten -DEMSCRIPTEN -fignore-exceptions -D__EMSCRIPTEN_major__=2 -D__EMSCRIPTEN_minor__=0 -D__EMSCRIPTEN_tiny__=30 -D_LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/Users/gaoding/github/emsdk/upstream/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -O3 -DSPDLOG_COMPILED_LIB -DDISABLE_TIME_STATISTIC -DDISABLE_IMAGE_FILE -DDISABLE_EXAMPLE -DEXTERN_DRIVEN_LOOP -DDISABLE_LOG -flto -I../ -I../../source -I../../source/codec -I../../source/audio -I../../source/util -I../../../XFoundation/3rdparty/spdlog/include -I../../../XFoundation/source -I../../../XFoundation/source/model -I../../../XFoundation/source/log -I../../../XFoundation/source/config -I../../../XPlayer/source/element -I../../3rdparty/ffmpeg/web/include -I../../3rdparty/libx264/web/include -I../../3rdparty/libfdk-aac/web/include -I../../3rdparty/libsox/web/include -I../../3rdparty/libgif -I../../3rdparty/libyuv/web/include ../XEncoderBinding.cpp -c -o /var/folders/ny/sm6l7r_n0md4m9d905w2qwyc0000gn/T/emscripten_temp_qg2bei6o/XEncoderBinding_0.o' failed (returned 1)
sbc100 commented 3 years ago

It would be very useful to know which change caused this regression. If you have time you could follow our bisect instructions to find out: https://emscripten.org/docs/contributing/developers_guide.html#bisecting

everywill commented 3 years ago

@sbc100 According to bisecting result, this commit caused the regression, related release

brendandahl commented 2 years ago

I'm unable to reproduce with the following example. If this is still an issue leave a comment and I'll reopon.

#include <emscripten/bind.h>
#include <emscripten.h>

using namespace emscripten;

class XEncoder                                                                          
{                                                                                        
public:                                                                                  
    XEncoder() = default;                                                               

    int open() {
        return 1;
    }                                                                                                                                                                             
};

XEncoder* makeXEncoder() {
    return new XEncoder();
}

bool open(XEncoder& self) {
    int openResult = self.open();
    if (openResult) {
        return true;
    }
    return false;
}
EMSCRIPTEN_BINDINGS(decoder_module) {
     class_<XEncoder>("XEncoder")
        .constructor(&makeXEncoder, allow_raw_pointers())
        .function("open", &open);
 }