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

Warn for Use of Symbol from Indirectly Included Header/Included Header from which No Symbols are Used #839

Open
ghost opened this issue Jan 26, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Jan 26, 2025

[yes, this is a duplicate of #234 and #236. Those issues were closed due to testing on an entire codebase rather than minimal test cases first. I think it's worth giving them another shot, without that pollution.]

Consider the following files:

// a.h

int f(char a) { /* ... */ }
//b.h

#include "a.h"
// c.c

#include "b.h"

void g() {
  // ...
  int n = f(x);
  // ...
}

c.c depends indirectly on a.h. Technically sound, but a real pest for compilation. I propose a flag, -Windirect-header, to detect and warn for this.

The latter idea is self-explanatory. Unused headers may not be as big a pest for compilation, but they still clutter the code and make it harder to trace dependencies. I propose -Wunused-header for this.


So as not to pollute the compile log, such warnings would ideally be printed per header rather than per reference, i.e.:

WARN: File main.c depends on header aux.h via route.h [using symbols jackConnect, jackStatus]
WARN: File main.c depends on header usb.h via route.h [using symbols jackPoll, jackBroadcast]
...

A wrinkle in this idea is that many projects have "meta-headers", that is, header files that only serve to indirectly provide a lot of smaller headers in one. Indirect warnings via these, and unused warnings within them, are frivolous. A solution would be some way to mark such headers as transitive, for instance by --transitive janet.h,zmq.h, thus disabling all such warnings.

@Vexu Vexu added the enhancement New feature or request label Jan 27, 2025
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

No branches or pull requests

1 participant