3

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:

Supremum
  • 542
  • 7
  • 23
  • Related question: http://stackoverflow.com/q/31220154 – Kerrek SB Jul 05 '15 at 13:36
  • 2
    `The only difference between the programs is the kind of entity used (struct or int)` **false**: first: `i` is a *data type*; second: `i` is a *variable* – bolov Jul 05 '15 at 13:37
  • `struct i {};` is a data type but `int i;` is a variable. Perhaps, that makes difference. – Piotr Siupa Jul 05 '15 at 13:38
  • 1
    [GCC](http://rextester.com/UDXDX90275) and [MSVC](http://rextester.com/VYMX33424) both report an error for the first program. I believe it is indeed ill-formed per **[basic.scope.declarative]/4** and that clang is incorrect in accepting it. – Igor Tandetnik Jul 05 '15 at 17:36

1 Answers1

2

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

Supremum
  • 542
  • 7
  • 23