C++ namespaces

Martin von Loewis martin@mira.isdn.cs.tu-berlin.de
Fri Feb 13 10:58:00 GMT 1998


I'd like to present a new implementation for C++ namespaces. This is
entirely new code, and therefore quite buggy. At this time, I'd like
to get feedback on the overall implementation approach. Also, testing
the code would be helpful. Please expect to totally break your C++
compiler when applying this patch.

So, here is the feature list:
Implemented:
- namespace-declarations
- unqualified and qualified lookups in namespaces
- using-directives (using namespace <foo>)
- namespace aliases (namespace <foo> = <bar>)
- name mangling for names inside namespaces
Still missing:
- using-declarations (using <foo>::<bar>)
- accessing overloadeded functions that come from multiple namespaces
Known limitations:
- On qualified lookup of namespace members, only direct members are
  considered. Can anybody confirm that this is not ISO C++ semantics?
- namespace aliases are allowed in using directives and as rhs values
  of namespace aliases. Same question.
Untested:
- extern "C" inside namespaces
- templates and their instantiations inside namespaces
- there was an attempt to preserve the current implementation of
  std:: (ie. treating it as ::). It is not clear whether this works
  under all conditions. OTOH, the future of this feature itself is not
  clear

I've attached a patch, the ChangeLogs are inside. Here is a brief
overview over the implementation:
- The semantics of the GLOBAL_VALUE was changed. It is now a chain
  of NAMESPACE_BINDINGS, each pointing to a namespace and the original
  global value.
- All accesses to the GLOBAL_VALUE were changed to also provide a
  namespace. The selection of this namespace needs probably further review.
- the current_namespace was changed to be a NAMESPACE_DECL, instead of
  a list.
- there is a new in_namespace lang specific decl field, pointing to
  the namespace in which the decl was first seen. Currently only guaranteed
  to be set for namespaces themselves.
- there is a new global_namespace variable, pointing to ::. This is needed
  to record the using directives in ::
- For each namespace, there are two lists of namespaces: the using and the
  users list. On each namespace directive, these are modified, and the
  changes are propagated to all users of a namespace. Also, for each
  used namespace, the common ancestor is computed, for efficient unqualified
  lookup.

Please let me know what you think.

Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: namespace1.gz
Type: application/x-gzip
Size: 15739 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/19980213/5d5561b9/attachment.bin>


More information about the Gcc mailing list