[cfe-dev] [PATCH] Ordinary name lookup for class and enum names in C++

Doug Gregor doug.gregor at gmail.com
Sat Apr 12 12:54:18 PDT 2008


The patch introduces support for ordinary name lookup of class and
enum names in C++. For example:

  class C { };
  C c;

Incidentally, it also introduces support for declaring classes with
"class" in C++, but that's rather trite.

Interesting bits in this patch:
  - Sema::ActOnTag: In C++, we introduce an implicit typedef into the
same scope as the tag type. This allows the name of a class or enum to
be found via ordinary name lookup. Note that we don't introduce this
implicit typedef if there is already a declaration with that name,
because the existing declaration takes precedence, e.g.,
      int D(int);
      class D { };
      // ordinary name lookup of "D" finds the function. Use "class D"
to get to the class.

  - Sema::ActOnDeclarator: Introducing a declaration for something
that has the same name as a class is okay; the new declaration hides
the class name. For example:
      class D { };
      int D(int);
      // ordinary name lookup of "D" finds the function. Use "class D"
to get to the class.
    To deal with this, we just go ahead and delete the implicit
typedef when a new declaration comes in.

I briefly considered eliminating the notion of the implicit typedef,
and instead modifying name lookup to look into both places in C++...
but this approach is cleaner.

  - Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clang-class-names.patch
Type: application/octet-stream
Size: 13504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080412/6d1f32b9/attachment.obj>


More information about the cfe-dev mailing list