ipr
ipr copied to clipboard
Template declarations with no definition.
Similar to issue #21 a forward declaration of a function template (with no body) is not possible as mapping is assumed to always have a result. It is similarly unclear how to represent class template decelerations with no definition.
template<typename T = int> void foo(T x);
template<typename T> void foo(T y) { };
template<typename T = int> struct classTemplate;
template<typename T> struct classTemplate{ };
In the case of function template mapping the .result()
should be a mapping of Parameters to a non-existent body.
In the case of a class template mapping the .result()
should be nothing
A possible solution to this is to make the result optional which was also suggested in #21.
A template declaration is a mapping that always produces a result: the declaration being parameterized (e.g. the current instantiation in the case of a class template definition). That declaration being parameterized may not have a definition itself, but the template is always a mapping.
So given
the template foo
is a named mapping that takes a type (defaulted to int
) and produces a function declaration.
Similarly,
template<typename T> void foo(T y) { }
is a named mapping that takes a type and produces the function definition.
In both cases the mapping is the mapping taking a type and producing a declaration.
Same logic for the class template declaration vs. class template definition.
I agree with the explanation of templates conceptionally and I misused definition in this case. The question I had is focused on how to represent a forward declaration of a template mapping and how that interacts with the current interface without resulting in a crash.
Let's focus on the code snippet below in isolation. To my understanding this would be represented as a Template Decl node which is a mapping of the template param T to the mapping of the function (param 'x' -> void). The problem here is that mapping of the function (not the template) has no result itself despite a Mapping being defined as always having a result in the interface.
template<typename T = int> void foo(T x);
So nothing about the Template Decl node is invalid but if you were to call util::view<Mapping>(template.result())->result()
on the above will result in a crash.
Since the definition here is missing - because it is just a non-defining declaration - isn't a Nothing
node an appropriate value for the result()