Bug 24986 - g++ is confused when function is defined inside and outside some namespace and called with '::' prefix
Summary: g++ is confused when function is defined inside and outside some namespace an...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.3
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-22 04:33 UTC by relf
Modified: 2011-12-22 18:15 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Testcase (bug.cpp) (131 bytes, text/plain)
2005-11-22 04:33 UTC, relf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description relf 2005-11-22 04:33:10 UTC
g++ (GCC) 4.0.3 20051111 (prerelease) (Debian 4.0.2-4)

g++ fails to compile the attached program with the following error

$ g++ bug.cpp
bug.cpp: In member function 'void B::foo(N::C)':
bug.cpp:12: error: cannot convert 'N::C' to 'long int' for argument '1' to 'void foo(long int)'

Note that removing namespace enclosure make the program compile fine.
Comment 1 relf 2005-11-22 04:33:59 UTC
Created attachment 10318 [details]
Testcase (bug.cpp)
Comment 2 Andrew Pinski 2005-11-22 05:13:41 UTC
I don't think this is a bug as what is happening is that :: is a qualified name and qualified namelookup (IIRC) does not find decls which are injected via using.
Comment 3 relf 2005-11-22 12:10:43 UTC
(In reply to comment #2)
> I don't think this is a bug as what is happening is that :: is a qualified name
> and qualified namelookup (IIRC) does not find decls which are injected via
> using.
> 

It does find. The following program (where `foo(long)` is commented out) is compiled fine.

===
namespace N {
  class C {};
  void foo(C) {};
}
using namespace N;

/* void foo(long) {}; */

class B {
public:
/*  void foo(long l) { ::foo(l); }; */
  void foo(C c) { ::foo(c); };
};

int main() {
  B b;
  return 0;
}
===

Comment 4 Wolfgang Bangerth 2005-11-23 05:31:50 UTC
I don't have chapter and verse to justify this, but icc and gcc agree
that they should reject this code
--------------
namespace N {
  class C {};
  void foo(C) {};
}
using namespace N;

void foo(long) {};

void bar() { C c; ::foo(c); };
---------------------
while they both accept the code with ::foo(long) removed:
---------------------
namespace N {
  class C {};
  void foo(C) {};
}
using namespace N;

void bar() { C c; ::foo(c); };
---------------------

One may certainly be tempted to find this confusing.

W.
Comment 5 Paolo Carlini 2011-12-22 18:15:19 UTC
Closing.