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:
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