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

unexpected behavior when explicitly instantiating a template #123

Closed
matkatmusic opened this issue Feb 20, 2019 · 5 comments
Closed

unexpected behavior when explicitly instantiating a template #123

matkatmusic opened this issue Feb 20, 2019 · 5 comments
Labels
bug Something isn't working

Comments

@matkatmusic
Copy link

matkatmusic commented Feb 20, 2019

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;
};
@andreasfertig
Copy link
Owner

Hello @matkatmusic,

you are totally right. I have trouble with the AST matchers. A quick fix broke existing tests. I need to take a closer look and how to handle this.

Andreas

@andreasfertig
Copy link
Owner

All right, I understood it. In the progress I found a second issue. Thanks for reporting the bug!

@andreasfertig
Copy link
Owner

Hello @matkatmusic,

can you be more specific? For what I see the output matches what you expect according to your initial post (and what I agree that it is correct). Maybe you checked to soon? After it appears as closed here it takes some time to do the build and upload it to the server.

@matkatmusic
Copy link
Author

My fault, it is working as expected. I must have checked too soon after you fixed it.

@andreasfertig andreasfertig added the bug Something isn't working label Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants