gbjie / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

Missing dependencies with templates #146

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Hello,

I noticed IWYU fails to catch dependencies of objects used in template 
functions.

In the sample I'm attaching, if we run IWYU on classB.cpp with these arguments:

F:\tests\templateTest\classB.cpp -IF:/tests/templateTest/ 
-IF:/external/mssdk/Include/ -DWIN32 -D_DEBUG -D_CONSOLE -Xiwyu --pch_in_code 
-Xiwyu --prefix_header_includes=keep

the result is this:

Source file f:/tests/templatetest/classb.cpp should remove:
- #include "templateTest/singleton.h"  // lines 5-5

If singleton.h is removed then the file won't compile because the template 
function DoTest uses this class.

If singleton.h is added to classA.h and we run IWYU on classA.cpp, then it will 
suggest to remove singleton.h as well. So no solution is valid according to the 
tool

Original issue reported on code.google.com by dpun...@gmail.com on 5 Jun 2014 at 6:51

Attachments:

GoogleCodeExporter commented 9 years ago
On Mac running IWYU on classB.cpp results in

    classA.h:15:9: error: use of undeclared identifier 'Singleton'

It doesn't look like classB.cpp requires singleton.h, so I've looked into why 
IWYU suggests to remove singleton.h when running on classA.cpp.  Looks like you 
are hitting issue #129.  Can you try to run IWYU on classA.cpp with 
-fno-delayed-template-parsing?  I.e. arguments are

    F:\tests\templateTest\classA.cpp -IF:/tests/templateTest/ -IF:/external/mssdk/Include/ -DWIN32 -D_DEBUG -D_CONSOLE -fno-delayed-template-parsing -Xiwyu --pch_in_code -Xiwyu --prefix_header_includes=keep

Original comment by vsap...@gmail.com on 5 Jun 2014 at 8:35

GoogleCodeExporter commented 9 years ago
I think this is the same as issue 129.

You could try passing -fno-delayed-template-parsing (Clang flag, so no -Xiwyu) 
as a workaround to see if that's actually the problem. Can you confirm if that 
helps, and I can merge the issues?

We don't have any ideas for solutions for this yet, but I think we should run 
it by the Clang list to see if they have any ideas.

Original comment by kim.gras...@gmail.com on 5 Jun 2014 at 8:35

GoogleCodeExporter commented 9 years ago

Thank you. Yes using that flag on classA.cpp fixes the suggestion of removing 
the include on classA.h. Before creating the sample I had a feeling it had to 
do with that, but when I tried using that flag in our codebase things weren't 
compiling anymore, so I discarded the solution :(

Original comment by dpun...@gmail.com on 5 Jun 2014 at 8:42

GoogleCodeExporter commented 9 years ago
Right, I don't think it's a solution either, it's just good to know it's the 
same problem. Merging.

Original comment by kim.gras...@gmail.com on 5 Jun 2014 at 9:06