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

            Bug ID: 17731
           Summary: Name Hiding is not properly handled.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected]
    Classification: Unclassified

$ cat name-hiding.cpp
// Hide class name with a function name
void foo1 () {
  class C {
  public:
    C() {}
    ~C() {}
  };
  int C();
  int ti = C();
  class C tc;
}

void goo1 () {
  int C();
  class C {
  public:
    C() {}
    ~C() {}
  };
  int ti = C();
  class C tc;
}

$ clang++ -target arm-none-linux-gnueabi -mfloat-abi=softfp -mfpu=neon
--sysroot=~/build_tools/gcc-4.6.1-cs/arm-2011.09 -Os -mthumb -c name-hiding.cpp

name-hiding.cpp:17:12: error: reference to 'C' is ambiguous
  int ti = C();
           ^

name-hiding.cpp:17:7: error: no viable conversion from 'C' to 'int'
  int ti = C();
      ^    ~~~

name-hiding.cpp:28:12: error: reference to 'C' is ambiguous
  int ti = C();
           ^

name-hiding.cpp:28:7: error: no viable conversion from 'C' to 'int'
  int ti = C();
      ^    ~~~

2 warnings and 4 errors generated.

(Warnings and notes are removed for clarity.)

>From C++ lang spec:

A class name or enumeration name can be hidden by the name of a variable, data
member,
function, or enumerator declared in the same scope. If a class or enumeration
name and a variable, data
member, function, or enumerator are declared in the same scope (in any order)
with the same name, the
class or enumeration name is hidden wherever the variable, data member,
function, or enumerator name is
visible.

Seems to related to this commit:

commit a41c97a5d1912ffd184381d269fd8e5a25ee5e59
Author: Richard Smith <[email protected]>
Date:   Fri Sep 20 01:15:31 2013 +0000

    Switch the semantic DeclContext for a block-scope declaration of a function
or
    variable from being the function to being the enclosing namespace scope (in
    C++) or the TU (in C). This allows us to fix a selection of related issues
    where we would build incorrect redeclaration chains for such declarations,
and
    fail to notice type mismatches.

    Such declarations are put into a new IdentifierNamespace, IDNS_LocalExtern,
    which is only found when searching scopes, and not found when searching
    DeclContexts. Such a declaration is only made visible in its DeclContext if
    there are no non-LocalExtern declarations.


    git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191064
91177308-0d34-0410-b5e6-96231b3b80d8

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to