-
Notifications
You must be signed in to change notification settings - Fork 386
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
forward declaration not suggested for type returned from function #1578
Comments
This is the default IWYU policy. Please read the docs: https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhatIsAUse.md I think it would be nice to add command-line flags to switch these policies off. |
Interesting. This is basically the "mission statement" I was referring to in #1568 (comment).
I second that. I doubt that each author will properly express their intend. And even if that is covered in code reviews there might still be cases slipping through. And with the function parameter case suggesting the forward declaration, depending on when you started to use include-what-you-use and the evolution of the code, you might end with either of the cases. I think it would be nice to be able to enforce a certain policy for consistency across the code. |
I think there should be three different policies: |
It could be more complex than that though as currently there are two different policies in place. They allow for either full or incomplete types if they are already being used and suggests the full type if a change is necessary. So there would be more cases:
|
If you're interested in short term local solution, simply replace the include with a forward decl, and iwyu should interpret that according to its policy. |
test.h
s.h
Analyzing a file including
test.h
will not suggest a forward declaration which would be sufficient.But if you are already using a forward declaration instead of the include it will report that everything is correct.
If the type is used as a function parameter it will suggest the forward declaration.
I am quite surprised but apparently it is legal: https://stackoverflow.com/questions/47817012/incomplete-types-as-function-parameters-and-return-values.
I am using include-what-you-use 0.22 on Manjaro Linux.
The text was updated successfully, but these errors were encountered: