[cfe-dev] Using declarations
Douglas Gregor
dgregor at apple.com
Thu Jun 11 08:52:26 PDT 2009
On Jun 11, 2009, at 5:02 AM, AlisdairM(public) wrote:
> I would be interested in any work on using declarations, as I have
> been
> scoping that out for my next project after the Unicode work.
>
> Again, I was looking for a simple idea (C++0x type alias - should be
> able to
> hook directly into typedef code) and discovered a much deeper hole.
> So my
> concern is that any work here looks ahead to all the possible
> directions
> that C++0x will go.
"using" got a lot more complicated in C++0x. Heck, it has more new
meanings than "auto"!
Still, I don't think it's all that hard to deal with these variants.
> In short, if we see the keyword 'using' we may be about to parse:
>
> i/ a using directive for namespaces
We have the "namespace" keyword, so this is easy to cope with.
> ii/ a C++98 using declaration
Since we turn nested-name-specifiers into a single token, this is
pretty easy to cope with. Although semantic analysis will have to
distinguish it from...
> iii/ a C++0x inheriting constructor declaration -> declares *a set* of
> constructors
... this one.
> iv/ a C++0x alias declaration => this declares a C++98 typedef name
This is easy to distinguish with two-token lookahead, although it'd be
better if we didn't need it.
> v/ a C++0x template alias, if using preceded by a template declaration
Same as above; we just have to cope with a template header.
> vi/ a number of concept-related variants that I don't quite grok yet.
These are for scoped concept maps.
> The current code is only annotated with the grammar for (i) and (ii)
Our general philosophy is: make C++98/03 work first, but design in
support for C++0x so that it's easy to implement later. Of course, we
love patches for C++0x features, too!
> Personally, I would rather see a broad set of test-cases before
> starting an
> implementation, as there are some nasty cases to catch such as
> different
> rules for duplicate identifiers at namespace or class scope etc.
So long as we have a decent test case with the implementation, I'm
happy. That said, Alisdair implies another important point: coming up
with test cases is very helpful for the development process, even when
we don't yet have an implementation!
- Doug
More information about the cfe-dev
mailing list