zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Check nested templates for instantiations

Open fklebert opened this issue 5 years ago • 0 comments

At the moment it is possible to instantiate a template in a different package and have a nested template (a template within the instantiated one) not being instantiated. This results in code split into two packages and therefore defeating the idea of the instantiate keyword.

I would like to at least see zserio issue a warning that nested templates have not been instantiated, because in most cases a designer would overlook this. Later we may even automatically do the instantiations, but at the moment I think a warning is good enough.

Example:

package templates;

struct OneTemplate<T, S>
{
  T value;

  AnotherTemplate<S> anotherTemplate;
};

struct AnotherTemplate<S>
{
  S someOtherValue;
};

The User package makes use of the template OneTemplate via instantiation:

package user;

import templates.*;

instantiate OneTemplate<uint8, uint16> UsedTemplate;

struct User
{
  UsedTemplate userTemplate;
  string userName;
};

This results in generated code (e.g. C++) with the following include: #include <templates/AnotherTemplate_uint16.h> which is not desired in that situation.

fklebert avatar Jul 06 '20 08:07 fklebert