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 specialization in header is mishandled #801

Open
shivanshu3 opened this issue Jun 4, 2020 · 1 comment
Open

template specialization in header is mishandled #801

shivanshu3 opened this issue Jun 4, 2020 · 1 comment

Comments

@shivanshu3
Copy link

shivanshu3 commented Jun 4, 2020

Given the following input, IWYU produces an incorrect output:

main.cpp:

struct Foo
{
	static constexpr int num = 10;
};

#include "NumGetter.h"

#include "IntegerWrapperFoo.h"

int dummy()
{
	NumGetter<Foo> x;
	return x.GetNum();
}

NumGetter.h:

template<typename T>
struct IntegerWrapper
{};

template<typename T>
struct NumGetter
{
	int GetNum()
	{
		return IntegerWrapper<T>::num;
	}
};

IntegerWrapperFoo.h:

template<>
struct IntegerWrapper<Foo>
{
	static constexpr int num = Foo::num;
};

IWYU output:

>include-what-you-use.exe main.cpp

main.cpp should add these lines:

main.cpp should remove these lines:
- #include "IntegerWrapperFoo.h"  // lines 8-8

The full include-list for main.cpp:
#include "NumGetter.h"  // for NumGetter
---

I am on the master branch of IWYU at commit b4838853e5c906854a616d9e975b53c164950174 from May 24 2020.

@shivanshu3
Copy link
Author

@kimgr I tried fixing this, and I've submitted a PR (#803)
Let me know what you think about this change. I applied this change on our internal fork of IWYU and it seems to work well and fixes the issue I was seeing originally.

If you think I'm on the right track, I will add a test and also look at some test failures. 22 tests were failing before my change, and 28 are failing after this change.

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

Successfully merging a pull request may close this issue.

1 participant