2

提供された最後の引数に特化した可変引数関数を作成しようとしています。

    // we take em all as long as they are convertible to string
    template<typename... Args>
    void warn(Args... args, string s){
        vector<string> joinable{args..., s};
        SMDiagnostic w(TUName, SourceMgr::DK_Warning,
                util::join(joinable));
        w.print("CGD.so", errs());
    }

    template<typename... Args>
    void warn(Args... args, Value const * v){
        string buffer;
        raw_string_ostream os(buffer);
        v->print(os);
        warn(args..., os.str());
    }

    template<typename... Args>
    void warn(Args... args, CallInst const * ci){
        warn(args..., dyn_cast<Value>(ci));
    }

そして、私はそれらを呼び出そうとします

warn(me, someCallInst);

しかし、clangは私に奇妙なエラーを与えます

error: no matching member function for call to 'warn'
       warn("We found a function usage that is not a call!! Ignoring\n", inst);
       ^~~~
../llvm_opt_pass/cgd.cpp:1062:8: note: candidate function not viable: requires 1 argument, but 2 were provided
                void warn(Args... args, CallInst const * ci){
                     ^
../llvm_opt_pass/cgd.cpp:1054:8: note: candidate function not viable: requires 1 argument, but 2 were provided
                void warn(Args... args, Value const * v){
                     ^
../llvm_opt_pass/cgd.cpp:1046:8: note: candidate function not viable: requires 1 argument, but 2 were provided
                void warn(Args... args, string s){

そのような可変個引数テンプレートを使用できるようにするには、どうすればよいですか?

4

0 に答える 0