我正在尝试编写一个可变参数函数,该函数将专注于提供的最后一个参数。
// 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){
我必须做什么才能使用这样的可变参数模板?