18

In [namespace.udecl]/10 you have the following example:

namespace A {
    int i;
}
namespace A1 {
    using A::i;
    using A::i; // OK: double declaration
}
void f() {
    using A::i;
    using A::i; // error: double declaration
}

This snippet compiles in clang.

Belloc
  • 6,318
  • 3
  • 22
  • 52
  • 1
    What practical problem does this cause you? – Lightness Races in Orbit Jul 04 '15 at 16:28
  • 1
    @LightnessRacesinOrbit: This question is a language-laywer question. There need not be any practical problems for such questions for them to be interesting. There are about the definition of the programming language. – Supremum Jul 04 '15 at 21:29
  • @Supremum: [_"if your question generally covers… a practical, answerable problem… then you’re in the right place to ask your question!"_](http://stackoverflow.com/help/on-topic) It might be interesting but it is not on-topic. – Lightness Races in Orbit Jul 05 '15 at 03:04
  • The answer to this related question solves this question: http://stackoverflow.com/questions/31224886/program-with-chaining-of-using-declarations-compiles-on-msvs-and-clang-but-not-o Observe that the example [namespace.udecl]/10 is incorrect and has just been changed in response to my related question. – Supremum Jul 06 '15 at 02:04
  • This question seems very related also: http://stackoverflow.com/questions/4252451/namespace-using-declaration-bug-in-gcc-vs2010 – Supremum Jul 06 '15 at 02:16
  • @Supremum Thanks for the links – Belloc Jul 06 '15 at 20:49

1 Answers1

7

The first is a declaration inside a namespace, and the multiple using statements could happen frequently using #includes. The second is inside a definition of a function, and you would never do that unless you made a mistake. You can't define the same symbol twice either, for example, but you can declare several times.

The using statement is also more than just a declaration. It is a bit stronger, as it imports a function from one namespace to another. For example, it can pull a protected base class member function into a derived class, making it public. It's almost a definition by linkage.

Mark Lakata
  • 19,989
  • 5
  • 106
  • 123
  • Could you provide a quote from the standard? – Belloc Jul 04 '15 at 15:14
  • The answer to this related question solves this question: http://stackoverflow.com/questions/31224886/program-with-chaining-of-using-declarations-compiles-on-msvs-and-clang-but-not-o Observe that the example [namespace.udecl]/10 is incorrect and has just been changed in response to my related question. – Supremum Jul 06 '15 at 02:00