Search code examples
c++clanglanguage-lawyerusing-declarationredeclaration

Redefinition inconsistency in clang between struct and int


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:


Solution

  • 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