Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template declarations with no definition. #86

Open
d-winsor opened this issue Nov 24, 2020 · 3 comments
Open

Template declarations with no definition. #86

d-winsor opened this issue Nov 24, 2020 · 3 comments
Assignees

Comments

@d-winsor
Copy link
Contributor

d-winsor commented Nov 24, 2020

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.

@GabrielDosReis GabrielDosReis self-assigned this Nov 25, 2020
@GabrielDosReis
Copy link
Owner

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.

@d-winsor
Copy link
Contributor Author

d-winsor commented Dec 2, 2020

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.

@GabrielDosReis
Copy link
Owner

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants