10
namespace A{
   int i;
}

int main(){
   using A::i;
   using A::i;
}

VS2010 - compiles fine

gcc (ideone) - compiles fine

Comeau - gives error ""ComeauTest.c", line 10: error: "i" has already been declared in the current scope using A::i;"

$7.3.3/8 - "A using-declaration is a declaration and can therefore be used repeatedly where (and only where) multiple declarations are allowed."

The example right there indicates that the code is indeed ill-formed.

So, is this a bug in GCC and VS2010?

EDIT 2:

Remove the multiple using directives as it was unrelated to the query on hand.

Chubsdad
  • 24,777
  • 4
  • 73
  • 129
  • 1
    My understanding is that it should be a bug in Comeau, not MSVC/GCC, for the same reason this is fine: `int main(){ extern int i; extern int i;}`. Obviously I'm missing something simple. – GManNickG Nov 23 '10 at 03:26
  • 2
    @GMan : Check out `7.3.3/8` once. – Prasoon Saurav Nov 23 '10 at 03:26
  • @Prasoon: Doesn't get more direct than that, thanks. – GManNickG Nov 23 '10 at 03:27
  • By the way, I want to kill the SO commenting system. First it complains about less than 15 characters. Then it complains about less than 15 seconds since last try. And so on. The darned system should whipped and flayed and shot with course-grained salt, then tortured, ridiculed, spit on etc. & drowned in undersea volcano – Cheers and hth. - Alf Nov 23 '10 at 03:28
  • 2
    @Alf: I agree [OneMoreCharNeededButI'llPutThisLongFillerTextInInsteadBecauseIAmIrritated] – James McNellis Nov 23 '10 at 03:31
  • @Alf: For sure, you can thank Atwood for this nonsense. For example: [here](http://meta.stackexchange.com/questions/35443/if-i-cant-comment-for-30-more-seconds-why-is-the-add-comment-button-enabled/35450#35450) or [here](http://meta.stackexchange.com/questions/35501/please-return-the-comment-rate-limit-to-a-flat-30-seconds). So stupid... – GManNickG Nov 23 '10 at 03:34
  • 1
    @GMan I still think that MSGC/GCC/Clang doesn't have it *wrong*. I don't think one can argue that comeau has it wrong because obviously the intent is that it is wrong, but saying that the others have it wrong seems to be a bit too heavy to me (because on what normative text is the intent based on?). See my comment on @Jame's answer. – Johannes Schaub - litb Nov 23 '10 at 23:11
  • @Johannes: Glad I'm not alone in thinking it should be fine. :) – GManNickG Nov 23 '10 at 23:21
  • This is [CWG issue 36](http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#36) – M.M Jan 16 '15 at 05:29

2 Answers2

9

The example you refer to is known to be inconsistent. The committee hasn't yet fixed this.

So, is this a bug in GCC and VS2010?

I don't think it's a bug in either of GCC/VS2010/Clang or Comeau. It appears to be a bug in the C++ Standard. In these cases, compile writers have to make up their mind on what is most viable. If you remove the example in question, then 3.3/4 states the example is valid: "Given a set of declarations in a single declarative region, each of which specifies the same unqualified name, ... they shall all refer to the same entity, or all refer to functions and function templates; or ...".

The question arises, as discussed in the linked issue, what 7.3.3/8 refers to when it says "declarations", which the committee didn't reach consensus about. And so, until then 3.3/4 applies for GCC/VS2010 and Clang, while Comeau chooses to use some other semantics.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
1

Yes you are right. This is indeed a bug in g++, MSVC++ and Clang. Comeau has got it correct.

As you said 7.3.3/8 says

A using-declaration is a declaration and can therefore be used repeatedly where (and only where) multiple declarations are allowed

The following code snippet is also given.

void f()
{
    using A::i;
    using A::i;  //error: double declaration
}

Similarly your code is ill-formed too.

Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345