内联名称空间和扩展名称空间 [英] inline namespace and extension namespace

查看:89
本文介绍了内联名称空间和扩展名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了有关命名空间定义的部分. N3797的第7.3.1条说:

I read the section about namespace definition. Clause 7.3.1 of N3797 said:

inline关键字可以在扩展名空间定义中使用 仅当以前在原始名称空间定义中使用过它时 该名称空间.

The inline keyword may be used on an extension-namespace-definition only if it was previously used on the original-namespace-definition for that namespace.

请考虑以下代码段:

namespace M
{
    int h;
}

inline namespace M
{
    int j = 6;
}

在使用-std=c++11和不使用该选项的情况下,编译成功.你能解释一下这种行为吗?是g++错误吗?

It compiled successful both with the -std=c++11 and without that option. Can you explain that behavior? Is it a g++ bug?

推荐答案

对标准的所有引用都是明确的:不允许这样做.

Vour reference to the standard is explicit: this is not allowed.

使用Clang ++,我会收到有关以下内容的非常清楚的错误消息:

Using Clang++ I get the very clear error message about this:

Test0614-1.cpp:17:18: error: non-inline namespace cannot be reopened as inline
inline namespace M
                 ^
Test0614-1.cpp:12:11: note: previous definition is here
namespace M
          ^

因此,这绝对是g ++中的错误.顺便说一下,它是在这里报告的: https://gcc.gnu.org/bugzilla /show_bug.cgi?id=53402

So it's definitively a bug in g++. By the way, it's reported here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53402

编译器接受该标准的早期版本的内联名称空间并且至少没有警告的事实似乎是一个问题.在2010年,该错误已被报告为错误,应该予以修复: https://gcc .gnu.org/bugzilla/show_bug.cgi?id = 43824

The fact that the compiler accepts inline namespace for previous version of the standard and without at least a warning seems to be an issue. This was already reported as bug in 2010 and should have been fixed: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43824

这篇关于内联名称空间和扩展名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆