为什么以下示例不能在clang上编译

时间:2017-02-16 15:00:26

标签: c++ clang

template<class ...Args>
using Fn = int(*)(Args... args);

template<class ...Args>
void CreateHandler(const Fn<Args...> ) {

}

int my_fun() {
    return 1;
}

void CreateGenericHandler() {
    Fn<> s = & my_fun;
    CreateHandler<>(s);
}

int main(int, char *[]) {
    return 0;
}

给出以下编译错误

main.cpp:19:5: error: no matching function for 
call to 'CreateHandler'
     CreateHandler<>(s);
     ^~~~~~~~~~~~~~~ 
 ../template_bug_testing/main.cpp:9:6: note: candidate template ignored: > failed template argument deduction void
 CreateHandler(const Fn<Args...> ) {

并使用命令构建

clang++ -c -pipe -g -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -Wall -W -fPIC

其中clang版本信息是

Apple LLVM version 7.3.0 (clang-703.0.16.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode- beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

但msvc或gcc上不会发生此错误。

0 个答案:

没有答案