-
Notifications
You must be signed in to change notification settings - Fork 7
CWG2781 [basic.def.odr] "... for D itself, the behavior is as if there is a single entity with a single definition" renders the complere ODR teethless #402
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
Comments
Possible duplicate of #271 |
Unfortunately #271 is closed and the wording is still highly ambiguous. I see no way to read p14 and p15 to make the first example IFNDR and the second example wellformed. |
If enough people want #271 fixed, maybe it will get reopened :) |
A clarification question: For your initial example, I'm missing a bit of context:
Is this supposed to appear in several translation units of a program? Also, you seem to be referring a rule in p15 that is now in p16:
I feel "For each such entity" clearly refers to "corresponding entities defined within each definition of D". Are we just missing something like "For each such entity and for D itself where these requirements are satisfied, the behavior is..." ? |
Yes, sorry. I meant to put "static" in front of "int x". The code is meant to appear in multiple TUs.
I think this issue report is a dupe of #271 (which I definitely should have read more closely before opening mine). Even if you add the text "where these requirements are satisfied", then it means that for cases like in #271 or in cases like in my lambda example (where there is a local declaration of a struct - that albeit is made to have the token sequence of the lambda expression for ODR purposes, still declares a new local type - that would presumably, because it has no linkage, then declare a different entity in each of the TUs that the inline definition appears in). There is a note in [dcl.inline]p6 (https://eel.is/c++draft/dcl.inline#6) that says
However, the normative text that guarantees this appears to rely entirely on the "for D itself, the behavior is as if there is a single entity with a single definition" part of the ODR. So it's important that we first apply that rule, to then satisfy the requirement in p14 that names within the inline definition that happen to refer to entities defined therein refer to the same entity. Inserting "where these requirements are satisfied" reverses the order, however, and therefore makes the lambda example and the example in #271 fail with IFNDR. |
I think I see now what you are saying, which I was missing at first. I think it works if we only apply p15 to D if the requirements are satisfied, but apply them to "each such entity" regardless of whether they are satisfied (in the check of D, but not in the (recursive) check for each of the entities. So in the recursive checks, all definitions are checked again. So I think I would recommend:
Maybe with a clarifying note in the comments. |
First of all, let's please use the latest working draft https://isocpp.org/files/papers/N4958.pdf for any specific discussions. I believe it contains minor editorial improvements that may or may not be helpful for this discussion. At least, we should use its paragraph number for further discussion. Furthmore, let's consider #271 dead (even though this issue might be a duplicate), and make sure we reach a common understanding here. Please bear with me while I walk through the examples that have been presented here, and please tell me where I take the wrong turn according to your reading of the wording. All references are to [basic.def.odr].
Here, we want to find out whether the definition of p14.2 tells use we need to check "the following requirements". p14.5 says we need to check the lookup results for Now, on to the case in #271, slightly simplified:
We again arrive at p14.5 for D = f2. We have to check whether p16 says "These requirements also apply to corresponding entities defined within each definition of D". So, the requirements apply (recursively) to So, we consider "a" to have a single definition, and we use that knowledge when resuming the checking for D = f2, where we also reach the "single definition" conclusion. I do agree that a reference to the recursive requirements checking on |
Why do we not prefer to rearrange a similar assumption to the proposed wording
before the requirement list that is used to check |
The ODR applies to multiple definitions of the same entity. For example this is rendered IFNDR by https://eel.is/c++draft/basic.def.odr#14.5 :
But there is a rule in p15:
Therefore, the above code example is not anymore IFNDR because the behave is "as if" there is only a single definition of f? I hear that this is not the case, because the requirements still apply. So if we change
f
to this:If we check the requirements in p14 and then for the remainder of the spec behave as if there was only a single definition of D (which is what prior specs said), then the requirement in p14 that says this is violated and the function
f
becomes IFNDR:The text was updated successfully, but these errors were encountered: