【发布时间】:2015-04-17 15:45:49
【问题描述】:
我在使用 Visual Studio 2013 Community 和 2013 年 11 月 CTP 进行编译时偶然发现了我的程序中的一个奇怪行为。以下程序编译并打印“true”,而预期的行为是它会打印“false”,这是 GCC and clang 所做的。
我已经在我的设置以及以下站点上测试了此代码:http://webcompiler.cloudapp.net/(声称 VS 编译器版本 19,也打印“true”)、http://codepad.org/、http://www.tutorialspoint.com/compile_cpp_online.php 和其他一些站点。
我不确定这里的正确行为是什么,或者下面的代码是否实际上是正确的 C++ 代码,所以我很困惑。如果有人能对这里发生的事情有所了解,那就太好了。
#include <stdio.h>
#include <typeinfo>
template <typename T>
struct foo
{
template <typename U>
static void bar() {}
};
template <typename T>
void baz() {
puts(typeid(&foo<T>::template bar<int>) == typeid(int) ? "true" : "false");
}
int main() {
baz<double>();
}
编辑:
感谢 Reddit,我设法让 STL 注意到了这个错误,STL 说他已经报告了这个问题,并将在 VS 2015 RTM 中修复:http://www.reddit.com/r/cpp/comments/2zs2ob/vc_2015_rtm_what_do_you_want_it_to_have/cpm01wr
【问题讨论】:
-
更正了您的包含并进行了一些清理和格式化。使用您的编译器是否仍然显示错误? coliru.stacked-crooked.com/a/1a04edd5a5b40d19
-
那么您提交错误报告了吗?如果是这样,您能否在此处链接到它,以便我们对其进行投票?
-
很遗憾,我收到“您无权提交此连接的反馈”。当我尝试使用 Visual Studio Connect 报告错误时出错。
标签: c++ visual-studio templates visual-c++