为什么clang ++ 3.5无法编译此代码片段而clang ++ 3.6可以编译它?

时间:2015-07-07 16:51:25

标签: gcc g++ clang llvm clang++

此代码段无法使用clang ++ 3.5进行编译,但可以使用clang ++ 3.6进行编译。我搜索https://llvm.org/bugs/,似乎找不到任何关于此的错误。那么为什么这段代码片段无法在clang ++ 3.5中编译? g ++没有这个问题。提前谢谢。

void F() {}

template <typename T>
class Option {
  public:

  Option(const T &) {}

  Option(T &&) {}

  template <typename U>
  Option(const U &) {}

};

class Fork {
  public:

  Fork(const Option<void (*)(void)>&) {}

};


int main() {
  Fork fork(F);
}

使用clang ++ 3.5编译错误

test.cpp:25:13: error: conversion from 'void ()' to 'const Option<void (*)()>' is ambiguous
  Fork fork(F);
            ^
test.cpp:7:3: note: candidate constructor
  Option(const T &) {}
  ^
test.cpp:9:3: note: candidate constructor
  Option(T &&) {}
  ^
test.cpp:12:3: note: candidate constructor [with U = void ()]
  Option(const U &) {}
  ^
1 error generated.

我的铿锵++版

clang++ --version
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

1 个答案:

答案 0 :(得分:0)

clang ++ 3.5编译器可能无法识别Option中与void ()匹配的任何构造函数。这可能是因为const Option<void (*)()>不明确造成的。

您可能会发现有用的其他网站: LLVM Open Source Lib

PS:我想将此作为评论发布,但我不是50代。

相关问题