Redefinition inconsistency in clang between struct and int

大城市里の小女人 提交于 2019-12-22 11:30:52

问题


The following program gives no error when compiling with clang:

namespace X {
    struct i {};
}

namespace Y {
    using X::i;
    struct i {};
}

int main() {}

Let's use int instead of struct, then we get:

namespace X {
    int i;
}

namespace Y {
    using X::i;
    int i;
}

int main() {}

This program gives a redefinition error when compiling with clang.

The only difference between the programs is the kind of entity used (struct or int), but one compiles without errors and the other gives a redefinition error.

Does this indicate a bug in clang? Maybe the standard is ambiguous what a redefinition is when it comes to using-declarations. But shouldn't a compiler make its interpretation consistently?

The programs can be compiled here:

  • http://melpon.org/wandbox/permlink/Cixqs9EJcxeYb53E
  • http://melpon.org/wandbox/permlink/QmZ8ehXyozvKnZST

回答1:


As Igor Tandetnik said, it is ill-formed due to [basic.scope.declarative]/4 and there is a bug in clang.

The bug has now been confirmed and fixed. See: https://llvm.org/bugs/show_bug.cgi?id=24033



来源:https://stackoverflow.com/questions/31230903/redefinition-inconsistency-in-clang-between-struct-and-int

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!