[LLVMbugs] [Bug 12261] New: C language linkage and same name should refer to same variable

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 12 22:58:14 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=12261

             Bug #: 12261
           Summary: C language linkage and same name should refer to same
                    variable
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nlewycky at google.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


We don't implement this passage in [dcl.link]p6:

  "Two declarations for a variable with C language linkage with the same name
(ignoring the namespace names that qualify it) that appear in different
namespace scopes refer to the same variable."

Testcase:

  namespace A {
    extern "C" int i;
    namespace B {
      extern "C" int i;
    }
    using namespace B;
  }
  using namespace A;

  void func() {
    i = 0;
  }

nlewycky at ducttape:~$ llvm/Debug+Asserts/bin/clang test.cc
test.cc:13:3: error: reference to 'i' is ambiguous
  i = 0;
  ^
test.cc:3:18: note: candidate found by name lookup is 'i'
  extern "C" int i;
                 ^
test.cc:6:20: note: candidate found by name lookup is 'i'
    extern "C" int i;
                   ^
1 error generated.


Per the standard, those two 'int i's are the same variable in spite of the fact
they're declared in different namespaces, so the lookup should not be ambiguous
as it only found one unique variable (twice).

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list