TemplateTypeParmDecl declaration context

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

TemplateTypeParmDecl declaration context

Abramo Bagnara-2

In my simple mind I'd have guessed that declaration context for
TemplateTypeParmDecl was the containing template, but:

1) in current clang this is not true in both (as neither of two template
container nodes is a decl context):

template <typename T>
T f(T x) {
}

template <typename T>
struct s {
  static int v;
};

2) here there is no container to use as declaration context

template <typename T>
int s<T>::v;

I'm missing something about concept of declaration context?

That apart, IMHO and intuitively I'd say that a container for 2) would
be a very good thing.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: TemplateTypeParmDecl declaration context

Douglas Gregor

On Jun 18, 2010, at 10:34 AM, Abramo Bagnara wrote:

>
> In my simple mind I'd have guessed that declaration context for
> TemplateTypeParmDecl was the containing template, but:
>
> 1) in current clang this is not true in both (as neither of two template
> container nodes is a decl context):
>
> template <typename T>
> T f(T x) {
> }
>
> template <typename T>
> struct s {
>  static int v;
> };

The issue with template parameters is that they are created before we've created the AST node that would normally contain them, e.g., we need to build the TemplateTypeParmDecl for each 'T' in this example before we create the FunctionTemplateDecl or ClassTemplateDecl nodes. The same issue occurs with ParmVarDecls; there, we create the ParmVarDecls with the translation unit as their context. Then, when we add those ParmVarDecls to a FunctionDecl, we change the declaration context. I think it makes sense for us to do the same thing with template parameters (all three kinds).

> 2) here there is no container to use as declaration context
>
> template <typename T>
> int s<T>::v;

This is more tricky, since an out-of-line static data member is not really a context that holds other declarations: it's just a reflection of something that exists within the class template itself. If anything really owns the template parameter, perhaps it's s<T>?

> I'm missing something about concept of declaration context?


I don't think so. (1) is a (probably benign) bug, while (2) is a strange corner case we haven't worked out.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev