[LLVMdev] extern "C" and namespaces

Karen Shaeffer shaeffer at neuralscape.com
Thu Sep 19 18:50:41 PDT 2013


On Thu, Sep 19, 2013 at 11:50:52PM +0000, Riyaz Puthiyapurayil wrote:
> Can someone confirm whether the following is a known clang bug? I am having a lot of trouble compiling some old legacy code due to this error. I know "using namespace" is horrible but that doesn't make it illegal (g++ accepts this). The fix is easy but there are just too many instances of this in the legacy code. The following is not from the code I am trying to compile but is derived from an example in the C++11 standard (7.3.4 note 6)
> 
> foo.cpp:
> namespace A {
>     extern "C" int g();
>     extern "C++" int h();
> }
> namespace B {
>     extern "C" int g();
>     extern "C++" int h(int);
> }
> using namespace A;
> using namespace B;
> void f() {
>     g(); // okay: name g refers to the same entity
>     h(); // okay: overload resolution selects A::h
> }
> 
> foo.cpp:12:5: error: call to 'g' is ambiguous
>     g(); // okay: name g refers to the same entity
>     ^
> foo.cpp:2:20: note: candidate function
>     extern "C" int g();
>                    ^
> foo.cpp:6:20: note: candidate function
>     extern "C" int g();
>                    ^
> 1 error generated.

--- end quoted text ---

Hi Riyaz,
Based on the example in the C++11 standard at 7.3.4 note 6, which you have literally
cut and pasted as your example, it has to be a bug for c++11. The standard asserts
"okay: name g refers to the same entity". It's valid code.

enjoy,
Karen
-- 
Karen Shaeffer                 Be aware: If you see an obstacle in your path,
Neuralscape Services           that obstacle is your path.        Zen proverb



More information about the llvm-dev mailing list