Skip to content

unexpected behavior when explicitly instantiating a template #123

@matkatmusic

Description

@matkatmusic

I'm not sure what the expected behavior is, but this snippet shows no template instantiation code being generated:

template<typename T>
struct Person
{
	int age, heightInInches;
	T distanceTraveled = T(); //default value
	float hairLength, GPA;
	unsigned int SATScore;

	T run(T speed, bool startWithLeftFoot);
};

template<typename T>
T Person<T>::run(T speed, bool left )
{
	return speed + (left ? 1 : 0);
}

template struct Person<int>;

int main()
{
	Person<int> f;
	auto x = f.run(2, true);
}

If you comment out the template struct Person<int>; it generates the expected template code.
Any ideas on why this happens?

I was expecting to this:

/* First instantiated from: insights.cpp:22 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
struct Person<int>
{
  int age;
  int heightInInches;
  int distanceTraveled = int();
  float hairLength;
  float GPA;
  unsigned int SATScore;
  int run(int speed, bool left)
  {
    return speed + (left ? 1 : 0);
  }
  
  // inline Person() noexcept = default;
  // inline constexpr Person(const Person<int> &) = default;
  // inline constexpr Person(Person<int> &&) = default;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions