[module.import/6] last sentence:
A header unit shall not contain a definition of a non-inline function or
variable whose name has external linkage.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
this came up during discussion of other header unit constraints, we had not implemented it yet.
found a test case where we'd accidentally broken this rule too.
LGTM generally.
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
13076–13077 | getLangOpts().CPlusPlus20 is redundant. It is also good to define a helper interface withinHeaderUnit in Sema (not required). | |
15238–15239 | ditto |
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
13076–13077 | I do not mind making this change - but note that the constraint is specific to C++20 and there are some people who want to remove it (the constraint). I guess you meant getCurrentModule() ? |
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
13076–13077 |
Got it. Let's make it when it comes true. It won't be a big deal.
It looks a little bit better to me to not access ModuleScopes directly. |
OK so this is what I plan to land assuming testing goes OK.
I suspect that this might cause some user code to flag errors - there are quite a number of ODR violations "in the wild".
clang/lib/Sema/SemaDecl.cpp | ||
---|---|---|
13076–13077 | revised now (I added the helper). |
I forgot we need to mention such changes in https://clang.llvm.org/docs/ReleaseNotes.html#potentially-breaking-changes.
It will not break any existing compilation (we accept headers with non-inline external definitions as textual includes, that has not changed). What I mean is that such headers will not be accepted as Header Units - and I am sure some users will consider that to be a bug (even though the problem is that the header is not ODR safe).
So it's not a change that breaks existing code - because no-one has Header Units in existing code.
So it's not a change that breaks existing code - because no-one has Header Units in existing code.
We can't assume this. Since we already said people can try to use header units in clang15. We can't assume there is nobody using header units just because they don't tell us. In fact, I've seen some bug reports about header units recently. So there are people (try to) using header units at least. So I think we should better to mark it in the potential breaking section.
getLangOpts().CPlusPlus20 is redundant. It is also good to define a helper interface withinHeaderUnit in Sema (not required).