【问题标题】:Redefinition inconsistency in clang between struct and intstruct和int之间的clang重新定义不一致
【发布时间】: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; 是一个变量。也许,这会有所不同。
  • GCCMSVC 都报告第一个程序的错误。我相信根据 [basic.scope.declarative]/4 确实格式不正确,并且 clang 接受它是不正确的。

标签: c++ clang language-lawyer using-declaration redeclaration


【解决方案1】:

正如 Igor Tandetnik 所说,由于 [basic.scope.declarative]/4 其格式不正确,并且存在 clang 中的错误。

该错误现已得到确认和修复。见:https://llvm.org/bugs/show_bug.cgi?id=24033

【讨论】:

    猜你喜欢
    • 2014-04-11
    • 1970-01-01
    • 2019-03-29
    • 2016-08-21
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    相关资源
    最近更新 更多