Re: Issue 1115 in include-what-you-use: IWYU pragma: export not effective for forward declared enum class

0 views
Skip to first unread message

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

unread,
Nov 14, 2022, 10:45:30 PM11/14/22
to include-wh...@googlegroups.com
Comment #15 on issue 1115 by justusranvier: IWYU pragma: export not effective for forward declared enum class
https://github.com/include-what-you-use/include-what-you-use/issues/1115

[This commit](https://github.com/Open-Transactions/opentxs/commit/480e13684446cf68f0908bbf4c60640a565a7cfb) is a case study in iwyu-0.18 to 0.19 regressions.

It took over a thousand no_forward_declare pragmas to restore the desired behavior.

Many of the suggestions produced by this version were erroneous and broke the build:

* If the underlying type of an enum is bool then iwyu will generate forward declarations with an underlying type of _Bool
* iwyu will suggest illegal forward declarations of scoped enums that are inside a class

About half of the thousand new pragmas I needed to add were in source files which raises another long standing issue with iwyu: it suggests forward declarations in cpp files and not only in header files. There are zero valid reasons for this tool to add a forward declaration to a cpp file so every suggestion is generates is a false positive which must be manually suppressed.


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

unread,
Nov 15, 2022, 2:05:01 AM11/15/22
to include-wh...@googlegroups.com
Comment #16 on issue 1115 by bolshakov-a: IWYU pragma: export not effective for forward declared enum class
https://github.com/include-what-you-use/include-what-you-use/issues/1115

> If the underlying type of an enum is bool then iwyu will generate forward declarations with an underlying type of _Bool

It really does... Thank you! I hope I can take a look at the weekend.

> iwyu will suggest illegal forward declarations of scoped enums that are inside a class

That's strange. I even wrote [a test case](https://github.com/include-what-you-use/include-what-you-use/blob/master/tests/cxx/enums.cc#L38) that it doesn't occur. Could you please provide a minimal repro?

> ... another long standing issue with iwyu: it suggests forward declarations in cpp files and not only in header files. There are zero valid reasons for this tool to add a forward declaration to a cpp file so every suggestion is generates is a false positive which must be manually suppressed.

I agree. Maybe, I'll make a PR in some better times...

But I just wonder why you don't want to place opaque declarations instead of suppressing them? Do you really have to change enum underlying types often? And even if you really do, it could be easily done just with auto-replacing. Though, a lot of changes may be in git diff in that case...


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

unread,
Nov 15, 2022, 11:28:12 AM11/15/22
to include-wh...@googlegroups.com
Comment #17 on issue 1115 by justusranvier: IWYU pragma: export not effective for forward declared enum class
https://github.com/include-what-you-use/include-what-you-use/issues/1115

> That's strange. I even wrote [a test case](https://github.com/include-what-you-use/include-what-you-use/blob/master/tests/cxx/enums.cc#L38) that it doesn't occur. Could you please provide a minimal repro?

I found the place where I though it happened and it turned out to be some ancient code that used old naming conventions so the namespace looking like a class name.

> But I just wonder why you don't want to place opaque declarations instead of suppressing them? Do you really have to change enum underlying types often?

It's happened in the past but it is not frequent usually I'm just adding new enumerations without changing the underlying type. Mostly it's a concern for DRY. One enum in particular is referred to in over 230 source and header files. If the declaration is duplicated in each one of those files that's 230 new sources of potential future update mistakes that don't need to exist.


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

unread,
Nov 15, 2022, 11:28:46 AM11/15/22
to include-wh...@googlegroups.com
Comment #17 on issue 1115 by justusranvier: IWYU pragma: export not effective for forward declared enum class
https://github.com/include-what-you-use/include-what-you-use/issues/1115

> That's strange. I even wrote [a test case](https://github.com/include-what-you-use/include-what-you-use/blob/master/tests/cxx/enums.cc#L38) that it doesn't occur. Could you please provide a minimal repro?

I found the place where I though it happened and it turned out to be some ancient code that used old naming conventions so the namespace looked like a class name.

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

unread,
Nov 19, 2022, 11:58:29 AM11/19/22
to include-wh...@googlegroups.com
Comment #18 on issue 1115 by kimgr: IWYU pragma: export not effective for forward declared enum class
https://github.com/include-what-you-use/include-what-you-use/issues/1115

I'm a little torn on this one:

* On the one hand, it sounds like IWYU is doing the right thing -- pushing forward-declarations to the leaf of the include graph wherever possible (this should give real savings in compile time)
* On the other hand, your use of bundling headers make sense to cut down on cruft (a single `#include` line can cover many forward-decls)

So it seems to me the problem is exactly what the issue title says: `IWYU: pragma export` doesn't work for forward-declarations. PR #1129 demonstrates the mechanics, I _think_ that could be made to work for `export` too, but it's a little tricky how to maintain a mapping from export comments to the actual decls that need to be affected.


Reply all
Reply to author
Forward
0 new messages