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:
Create a new decl class, UsingAliasDecl, derived form NamedDecl, mainly storing a pointer to the target decl.
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)
Handle parsing using declarations in classes (Parser::ParseCXXClassMemberDeclaration).
Define and implement Action::ActOnUsingDeclaration (both MinimalAction.cpp and SemaDeclCXX.cpp).
Where the declared using identifier is used in expressions (i.e. Sema::ActOnDeclarationNameExpr), substitute the target decl, i.e.:
if (UsingAliasDecl *UsingAlias = dyn_cast(D))
D = UsingAlias->getTargetDecl();
- 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.
using_decl_experimental.patch (16.9 KB)
cxx-using-declaration.cpp (497 Bytes)