【发布时间】:2015-09-22 17:13:33
【问题描述】:
以下程序在使用 clang 编译时没有报错:
namespace X {
struct i {};
}
namespace Y {
using X::i;
struct i {};
}
int main() {}
让我们用 int 代替 struct,然后我们得到:
namespace X {
int i;
}
namespace Y {
using X::i;
int i;
}
int main() {}
此程序在使用 clang 编译时出现重新定义错误。
程序之间的唯一区别是使用的实体类型(struct 或 int),但一个编译没有错误,另一个给出重新定义错误。
这是否表示 clang 中的错误?当涉及到 using-declarations 时,也许标准是模棱两可的。但是编译器不应该使其解释保持一致吗?
程序可以在这里编译:
【问题讨论】:
-
The only difference between the programs is the kind of entity used (struct or int)false:首先:i是一个数据类型;第二:i是一个变量 -
struct i {};是一种数据类型,但int i;是一个变量。也许,这会有所不同。
标签: c++ clang language-lawyer using-declaration redeclaration