未使用的功能允许在MSVC中未申报的名称空间

发布于 2025-02-13 16:21:06 字数 484 浏览 0 评论 0原文

我们出现了一个有趣的情况,即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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2025-02-20 16:21:06

通常,如果根本不使用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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文