Issue 1145 in include-what-you-use: Implicit cast through Ctor(T&&) removes include that is needed

0 views
Skip to first unread message

notifi...@include-what-you-use.org

unread,
Nov 22, 2022, 2:57:22 AM11/22/22
to include-wh...@googlegroups.com
New issue 1145 by honkstar1: Implicit cast through Ctor(T&&) removes include that is needed
https://github.com/include-what-you-use/include-what-you-use/issues/1145

Setup:

---BaseClass.h---
class BaseClass {};

---SubClass.h---
class SubClass : public BaseClass {};

--TestFile.h---

#include "SubClass.h"

template <typename T>
struct TObjectPtr2
{
public:
template <typename U> TObjectPtr2(U&& Object) : ObjectPtr(Object) {}
T* ObjectPtr;
};

struct TestClass
{
public:
TObjectPtr2<BaseClass> Foo;

TestClass(SubClass* InFoo) : Foo(InFoo) {}
};

Above code does not work.. it strips out #include of SubClass.h

If I change "U&& Object" to "U* Object" in TObjectPtr2 ctor it works fine.

I have attached verbosed logging of working and broken (they might not match the above names but is the exact same scenario).
Will debug this tomorrow but is happy for pointers (no pun intended :-))

[Broken.txt](https://github.com/include-what-you-use/include-what-you-use/files/10065112/Broken.txt)
[Working.txt](https://github.com/include-what-you-use/include-what-you-use/files/10065113/Working.txt)

Thanks,
Henrik


notifi...@include-what-you-use.org

unread,
Nov 22, 2022, 2:10:57 PM11/22/22
to include-wh...@googlegroups.com
Comment #1 on issue 1145 by honkstar1: Implicit cast through Ctor(T&&) removes include that is needed
https://github.com/include-what-you-use/include-what-you-use/issues/1145

When running with verbose 6 it outputs this in the working version (the one using "*")

Adding an implicit tpl-function type of interest: class SubClass
Adding a template-class type of interest: class BaseClass -> class BaseClass

When running with "&&", I get this output

Adding an implicit tpl-function type of interest: class SubClass *&
Ignoring unseen-in-fn-args template arg of interest: class SubClass *&
Adding a template-class type of interest: class BaseClass -> class BaseClass

I tried adding this to GetTplTypeResugarMapForFunctionNoCallExpr:
arg_type = RemovePointersAndReferencesAsWritten(arg_type);

That solved my problem. I will run IWYU on more of the code now and see if it too aggressively brings in includes or if this fix is a good one.



notifi...@include-what-you-use.org

unread,
Nov 22, 2022, 4:45:32 PM11/22/22
to include-wh...@googlegroups.com
Comment #2 on issue 1145 by kimgr: Implicit cast through Ctor(T&&) removes include that is needed
https://github.com/include-what-you-use/include-what-you-use/issues/1145

Hey, thanks for root-causing! I need to think a bit about that change... Does the test suite pass with the change? `./run_iwyu_tests.py` with `include-what-you-use` in the PATH.


notifi...@include-what-you-use.org

unread,
Nov 23, 2022, 2:27:22 AM11/23/22
to include-wh...@googlegroups.com
Comment #3 on issue 1145 by honkstar1: Implicit cast through Ctor(T&&) removes include that is needed
https://github.com/include-what-you-use/include-what-you-use/issues/1145

Thanks for the quick turnaround Kim (are you Swedish like me?)

I haven't run the tests yet. I've been debugging some other things, and I will report them too.. one I haven't figured out yet. Will report it in next issue


notifi...@include-what-you-use.org

unread,
Nov 23, 2022, 12:07:52 PM11/23/22
to include-wh...@googlegroups.com
Comment #4 on issue 1145 by kimgr: Implicit cast through Ctor(T&&) removes include that is needed
https://github.com/include-what-you-use/include-what-you-use/issues/1145

Cool, thanks. Yeah, I'm also based in Sweden.


Reply all
Reply to author
Forward
0 new messages