看一看這段代碼:奇怪鏘行爲
#include <iostream>
#include <string>
void foo(int(*f)()) {
std::cout << f() << std::endl;
}
void foo(std::string(*f)()) {
std::string s = f();
std::cout << s << std::endl;
}
int main() {
auto bar = []() -> std::string {
return std::string("bla");
};
foo(bar);
return 0;
}
編譯它
g++ -o test test.cpp -std=c++11
導致:
bla
像它應該做的。與
clang++ -o test test.cpp -std=c++11 -stdlib=libc++
編譯它會導致:
zsh: illegal hardware instruction ./test
而且隨着
clang++ -o test test.cpp -std=c++11 -stdlib=stdlibc++
編譯它也導致:
zsh: illegal hardware instruction ./test
鏘/ GCC版本:
clang version 3.2 (tags/RELEASE_32/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
gcc version 4.7.2 (Gentoo 4.7.2-r1 p1.5, pie-0.5.5)
任何有什麼建議是什麼問題?
在此先感謝!
我會說這是叮鐺中的一個錯誤 – 2013-04-03 21:30:39
僅供參考,有關[ud2和clang]的更多信息(http://stackoverflow.com/q/26309300/1708801) – 2015-03-19 14:47:25