未使用的功能允许在MSVC中未申报的名称空间
我们出现了一个有趣的情况,即MSVC未在模板类中检查未使用功能的命名空间分辨率。例如:
#include <string>
namespace
{
template<class Iterator>
struct Foo
{
Foo()
{
}
void parse(Iterator begin, Iterator end)
{
foo::string a(begin, end - begin);
}
};
}
using CharFoo = Foo<const char *>;
CharFoo fooParser;
int main()
{
}
这在MSVC中编译并运行良好,但是GCC和Clang都会出现错误。这在技术上是MSVC错误吗? C ++标准是否对这种情况说明这是否是错误?
We came an interesting case where MSVC doesn't check namespace resolution for unused functions in a templated class. For example:
#include <string>
namespace
{
template<class Iterator>
struct Foo
{
Foo()
{
}
void parse(Iterator begin, Iterator end)
{
foo::string a(begin, end - begin);
}
};
}
using CharFoo = Foo<const char *>;
CharFoo fooParser;
int main()
{
}
This compiles and runs just fine in MSVC, but gcc and clang both give an error. Is this an MSVC bug technically? Does the C++ standard say anything about this case as to whether or not this is an error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,如果根本不使用MSVC,则不会编译任何模板功能。大多数编译器在这一点上有所不同 - 他们总是检查代码(我不知道C ++标准说什么。)
In general MSVC does NOT compile any template functions if they are not used at all. Most compilers differ in that point -- they always check the code (where I do not know what the C++ standard says.)