Skip to content
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

Proposal: Warn for use of a symbol not declared in the same file or an explicitly included header #234

Open
ghost opened this issue Feb 4, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Feb 4, 2022

In C, if A.c #includes B.h, and B.c #includes C.h, then the symbols declared in C.h will be available in A.c. (Nope, this was a misconception. But indirect header dependencies are still a pest for compilation.) Depending on this behaviour makes locating definitions when reading source a potentially recursive process, as well as making compilation inefficient when abused on a large scale1. My proposal is for a warning that would catch this behaviour, encouraging explicit #includes if a symbol is to be used.

This warning trips if a symbol is used which is not declared in the same file or in a header explicitly #included in the file. The symbol need not be defined in these, only declared; this means C projects written with best practices will compile the same way with no additional warnings.

- "Make headers standalone": over 80 headers don't build standalone and
   depend on various accidental indirect dependencies they gain through
   other headers, especially once headers get their unnecessary dependencies
   removed. So there's over 80 commits changing these headers.

Footnotes

  1. https://lkml.org/lkml/2022/1/2/187

@Vexu Vexu added the enhancement New feature or request label Feb 4, 2022
@ghost ghost changed the title Proposal: -fstrict-headers mode to limit symbol visibility within a compilation unit Proposal: -Windirect-include for use of a symbol not declared in the same file or an explicitly included header Feb 5, 2022
@ghost ghost changed the title Proposal: -Windirect-include for use of a symbol not declared in the same file or an explicitly included header Proposal: Warn for use of a symbol not declared in the same file or an explicitly included header Feb 5, 2022
@marler8997
Copy link
Contributor

marler8997 commented Feb 5, 2022

I did not know about this option, I love it! (Oh wait, it sounds like it doesn't exist and you're suggesting it be added, in which case I love the proposal!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants