[cfe-dev] using declarations

John Thompson john.thompson.jtsoftware at gmail.com
Thu Apr 16 17:20:28 PDT 2009


Hi,

I've been experimenting with an implementation for using declarations that
I'd like to bounce off you, to make sure I'm going down the right path.
I've enclosed a patch of the current changes, in case you want to use them
now.  These are a high-level description of the key changes/additions so
far:

1. Create a new decl class, UsingAliasDecl, derived form NamedDecl, mainly
storing a pointer to the target decl.

2. Add parsing code to Parser::ParseUsingDeclaration.  (Note: the 'typename'
keyword is parsed, but the semantic actions elsewhere don't support type
using decls.  No attempt to parse the 'concept' stuff yet)

3. Handle parsing using declarations in classes
(Parser::ParseCXXClassMemberDeclaration).

4. Define and implement Action::ActOnUsingDeclaration (both
MinimalAction.cpp and SemaDeclCXX.cpp).

5. Where the declared using identifier is used in expressions (i.e.
Sema::ActOnDeclarationNameExpr), substitute the target decl, i.e.:

  if (UsingAliasDecl *UsingAlias = dyn_cast<UsingAliasDecl>(D))
    D = UsingAlias->getTargetDecl();
6. For the case of global or member functions with the same name as the
using declaration, in the semantic action functions dealing with same-named
functions, don't match a using declaration.  I'm hoping it doesn't matter if
the using decl hides a previous declaration of the same name.

Question:  Is the UsingAliasDecl class the right way to go, and is the name
okay?

Question:  When encountering a name corresponding to a using declaration in
an expression, is just substituting the target declaration okay? I'm worried
that losing the semantic information about an identifier in a statement or
expression corresponding to a using declaration might be an issue.  But just
substituting the target decl makes for simpler code so far.

 I'm writing a cxx-using-declaration.cpp test file, which will later have
examples from the C++ standard draft or comparible ones.  I've enclosed the
simple non-error case version I've used so far.  While I'm waiting for
feedback, I'll work on adding more test cases, and getting the 'using
typename' to work.

-- 
John Thompson
John.Thompson.JTSoftware at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090416/76adfb67/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: using_decl_experimental.patch
Type: application/octet-stream
Size: 17346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090416/76adfb67/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cxx-using-declaration.cpp
Type: application/octet-stream
Size: 497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090416/76adfb67/attachment-0001.obj>


More information about the cfe-dev mailing list