Incorrect forward declare suggested by iwyu

52 views
Skip to first unread message

Daniel Jump

unread,
Jan 9, 2015, 2:57:18 AM1/9/15
to include-wh...@googlegroups.com
Hi,

I ran into an incorrect forward declare suggestion and managed to trim it down to a minimal repro. Iwyu suggests that bar.h can forward-declare Foo, which is incorrect.

[foo.cpp]
#include <type_traits>
#include "foo.h"
#include "bar.h"

[foo.h]
struct Foo
{
   void Release();
};

[bar.h]
inline void Bar()
{
   static_cast<std::remove_pointer<Foo*>::type*>((Foo*)nullptr)->Release();
}

Kim Gräsman

unread,
Jan 11, 2015, 4:53:11 AM1/11/15
to include-wh...@googlegroups.com
Hi Dan,
That doesn't seem right. Just to make sure, your command-line was

foo_test$ include-what-you-use foo.cpp -Xiwyu --check_also=bar.h

right?

I can reproduce with this on my BSD machine. Can you add -Xiwyu -v7 to
your command-line and post the results? I'll experiment in the
meantime.

- Kim

Kim Gräsman

unread,
Jan 11, 2015, 1:54:44 PM1/11/15
to include-wh...@googlegroups.com
On Sun, Jan 11, 2015 at 10:53 AM, Kim Gräsman <kim.g...@gmail.com> wrote:
>
> On Fri, Jan 9, 2015 at 8:57 AM, Daniel Jump <bigw...@gmail.com> wrote:
>>
>> [bar.h]
>> inline void Bar()
>> {
>> static_cast<std::remove_pointer<Foo*>::type*>((Foo*)nullptr)->Release();
>> }

I've reduced this down to:

inline void Bar
{
std::remove_pointer<Foo*>::type x;
}

with the same result. It looks like IWYU is confused by the
typedef-of-template-arg in std::remove_pointer.

I ran it with -v7 and didn't get much more relevant information, so I
think this is a case that IWYU just fails to record.

I logged this as issue #169, thanks!

- Kim
Reply all
Reply to author
Forward
0 new messages