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

[headers] Is a header not necessarily a source file? #665

Open
cor3ntin opened this issue Jan 15, 2025 · 4 comments
Open

[headers] Is a header not necessarily a source file? #665

cor3ntin opened this issue Jan 15, 2025 · 4 comments

Comments

@cor3ntin
Copy link

In [headers] (technically library wording), we have

Each element of the C++ standard library is declared or defined (as appropriate) in a header (A header is not necessarily a source file)

Presumably, the intent here is to permit an implementation to make a set of declaration available when incanting #include <vector> through magic rather than by following steps 1-4 of translations

However, both [cpp.include] and [lex.phases] seem to apply to "headers" and seem to contradict the note in [headers]

A #include preprocessing directive causes the named header or source file to be processed from phase 1 through phase 4, recursively.

In [cpp.include], we also say "If the *header identified by the denotes an importable header [...]", and here "header" need not be a standard library header (as there can be non-standard importable headers).


We have talked about the lack of clarity in this area before, but I could not find an issue for it.

I think a solution would be on the lines of

  • Any source file whose content was included to the current processing unit through an #include directive is a header
  • Both source files and headers behave the same through phases 1-4
  • In [headers], rename header to standard library header
  • We should remove the possibility that standard library headers are not source files as I'm not aware of anyone using that capability, nor can i imagine anyone wanting to ever do something like that.
@jensmaurer
Copy link
Member

What's the observable differences for those approaches?

Since headers are supplied by the implementation, I think the as-if rule says you can't detect any difference.

@frederick-vs-ja
Copy link

IMO there's no actual defect here. But it seems to me that the suggestions can simplify and clarify the wording without changing normative requirements.

@cpplearner
Copy link

An implementation may use a Pre-Compiled Header (.pch file) when a header is requested. However, name lookup requires the point of declaration to be well-defined, which requires the declaration to exist as-if in a source file.

@frederick-vs-ja
Copy link

An implementation may use a Pre-Compiled Header (.pch file) when a header is requested.

Per [lex.phase] p1.1, IIUC, we can treat decoding PCH as an implementation-defined manner of mapping characters from the input file. So it's perhaps meaningless to allow a header not to be a source file.

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

No branches or pull requests

4 participants